我在我的计算机上本地开发了一个小型 Web 窗体应用程序,它运行良好,但是当我将它移动到另一台计算机时,我使用 AJAX 查询的 Web 服务失败了。
以下是相关代码:
/*Search for Event.country by name*/
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string[] GetVenues(string searchterm)
{
var _db = new MyApp.Models.EventContext();
var myResult = from e in _db.Events
where e.venue.Contains(searchterm)
select e.venue;
return myResult.Distinct().ToArray();
}
我怀疑我的问题出在 EventContext 类中的 OnModelCreating 方法上:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Event>().ToTable("events");
}
我从本地计算机备份数据库并在另一台计算机上恢复它,所以我怀疑我在 OnModelCreating 上做错了,因为表已经存在。我的假设正确吗?
这是我从 Firebug 查看的 Web 服务响应中收到的错误消息:
{"Message":"An exception occurred while initializing the database. See the InnerException for details.","StackTrace":"
at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase> b__4(InternalContext c)
at System.Data.Entity.Internal.RetryAction'1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action'1 action)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet'1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet'1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery'1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.Where[TSource](IQueryable'1 source, Expression'1 predicate)
at MyApp.WebServices.AutoComplete.GetVenues(String searchterm)","ExceptionType":"System.Data.DataException"}