Sql server 在sql server中看不到第一个生成的代码数据库,但它的行为就好像它已被创建一样
我有一个WCF呼叫我的EF。我已将WCF作为我的启动项目,其中的一项服务作为启动文件 当我运行这个项目并将正确的参数作为Seed方法中的参数传入时,我从Login方法返回了一个对象 这意味着数据库应该是在SQL server的本地服务器上创建的,对吗?。当我更改代码优先类时,我得到一个错误,声明模型已经更改,这是因为数据库已经存在,对吗 我可以在Visual studio Server explorer中看到该数据库,但它已断开连接,当我尝试单击它时,它会询问用户名和密码,而我尚未将其配置为在我的Web.Config中有用户名和密码 我的问题是什么。我想在SQL server中查看我的EF数据库 用户上下文Sql server 在sql server中看不到第一个生成的代码数据库,但它的行为就好像它已被创建一样,sql-server,entity-framework,wcf,ef-code-first,dbset,Sql Server,Entity Framework,Wcf,Ef Code First,Dbset,我有一个WCF呼叫我的EF。我已将WCF作为我的启动项目,其中的一项服务作为启动文件 当我运行这个项目并将正确的参数作为Seed方法中的参数传入时,我从Login方法返回了一个对象 这意味着数据库应该是在SQL server的本地服务器上创建的,对吗?。当我更改代码优先类时,我得到一个错误,声明模型已经更改,这是因为数据库已经存在,对吗 我可以在Visual studio Server explorer中看到该数据库,但它已断开连接,当我尝试单击它时,它会询问用户名和密码,而我尚未将其配置为在我
public class UserContext : DbContext
{
public DbSet<User> Users { get; set; }
public UserContext()
: base("Local")
{
Configuration.AutoDetectChangesEnabled = true;
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
Configuration.ValidateOnSaveEnabled = true;
}
}
Web.config
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<!-- local dev -->
<add name="Local" connectionString="server=.;database=TodoTest;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
尝试以管理员身份运行VS。
此外,公共ICollection任务{get;set;}应该是虚拟的 关于您的问题“我得到一个错误,说明模型已经更改,这是因为数据库已经存在?”答案是肯定的…:)
public class UserService : IUserService
{
public User Login(string username, string password)
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
throw new Exception("User name or password cannot be empty");
}
User user = null;
using (var userContext = new UserContext())
{
user =
userContext.Users.FirstOrDefault(
u => u.Username.Equals(username, StringComparison.InvariantCulture) &&
u.Password.Equals(password, StringComparison.InvariantCulture));
}
return user;
}
}
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<!-- local dev -->
<add name="Local" connectionString="server=.;database=TodoTest;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>