相关疑难解决方法(0)

实体框架代码优先 - 为什么我不能这样更新复杂属性?

我正在使用Entity Framework 4.1(代码优先)开展一个小型示例项目.我的课程看起来像这样:

public class Context : DbContext
{
    public IDbSet<Person> People { get; set; }
    public IDbSet<EmployeeType> EmployeeTypes { get; set; }
}

public class Person
{
    [Key]
    public int Key { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    virtual public EmployeeType EmployeeType { get; set; }
}

public class EmployeeType
{
    [Key]
    public int Key { get; set; }
    public string Text { get; set; }

    virtual public …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework ef-code-first entity-framework-4.1

28
推荐指数
1
解决办法
1万
查看次数

EF 4.1 SaveChanges不更新导航或引用属性

我首先使用代码,可以毫无问题地添加记录.正确创建数据库并且没有任何问题地播种.但是在我的编辑操作中调用SaveChanges()只会更新实体,而不会更新任何导航或引用属性.

我的模型的简化版本:

public class Contact : IMyBaseObject
{
    public Contact()
    {
       this.Delete = false;
       this.ContactTypes = new HashSet<ContactType>();
    }

    public int Id {get; set;}

    public string Name {get;set;}

    public bool Delete {get;set;}

    public virtual ICollection<ContactType> ContactTypes { get; set; }

    public virtual USState USState { get; set; }

}

public class ContactType : MyBaseObject
{
    public ContactType()
    {
    }

    public int Id {get; set;}

    public string Name {get;set;}

    public virtual ICollection<Contact> Contacts {get;set;}
}

public abstract class Territory : MyBaseObject …
Run Code Online (Sandbox Code Playgroud)

entity-framework entity-framework-4.1

17
推荐指数
1
解决办法
9207
查看次数