I have a WCF which makes call to my EF. I have made the WCF my start up project and one of the services in there a start up file.
When i run this project and pass in the right parameter as what i have in my Seed method, i get an object back from Login method.
This means the database should have been created on my local server in SQL Server right ?. When i change the code first classes, i get an error that the stating that the model has changed so this is because the database already exists right ?.
I can see the database in Visual studio Server explorer but it is disconnected and when i try to click on it it's asking for username and password when i have not configured it to have one in my Web.Config
What could be my issue. I want to see my EF database in SQL server.
User Context
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;
}
}
User
public class User
{
[Key]
public Guid Id { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Password { get; set; }
public ICollection<UserTask> Tasks { get; set; }
public User()
{
Tasks = new List<UserTask>();
}
}
User Service (WCF)
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;
}
}
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>