【发布时间】:2016-08-31 14:51:53
【问题描述】:
尝试使用 Entity Framework 将我的类映射到现有表时,我遇到了一些困难。我目前首先使用代码,但是在没有它的情况下创建了一个表,我无法将它映射到一个创建的模型。
我的班级:
[Table("AgentCallsByPartner")]
public class AgentCallsByPartnerModel
{
[Key]
public int AgentCallID { get; set; }
[Required]
public DateTime CallDate { get; set; }
public string CustomerID { get; set; }
public string AgentNo { get; set; }
public string AccountCreated { get; set; }
public string QuoteStarted { get; set; }
[Required]
public string GroupName { get; set; }
[Required]
public string GroupRollup { get; set; }
}
上下文
public DbSet<AgentCallsByPartnerModel> AgentCallsByPartner { get; set; }
这是我的桌子
但是当我尝试从数据库中获取用户时,我得到了一个异常
自数据库创建以来,DbContext 发生了变化......
那么我的错误是什么?谢谢
【问题讨论】:
-
您是否更新了迁移?如果模式改变,你应用 drop create new database 吗?
-
我没有,因为表是直接在sql server中创建的,我需要做些什么吗?
-
你有迁移的想法吗?
-
请检查我的答案
标签: c# .net entity-framework entity-framework-4 entity-framework-5