【发布时间】:2015-08-17 05:55:58
【问题描述】:
用户服务
我是第一个编码 EF 和 WCF 的新手,我创建了一个测试项目,其中包含一个 Webforms 项目、一个业务逻辑(代码优先类)、一个用于我的服务的 wcf 项目以及稍后的数据访问
这是我的 wcf 的启动文件。
public User Login(string username, string password)
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
throw new Exception("User name or password cannot be empty");
}
var userContext = new UserContext();
var user = userContext.Users.FirstOrDefault(u => u.Username.Equals(username, StringComparison.InvariantCulture) &&
u.Password.Equals(password, StringComparison.InvariantCulture));
return user;
}
用户上下文
public class UserContext : DbContext
{
public DbSet<User> Users { get; set; }
static UserContext()
{
Database.SetInitializer(new UserContextInitializer());
}
}
我错过了什么?
【问题讨论】:
标签: asp.net entity-framework wcf dbcontext