相关疑难解决方法(0)

虚拟成员在构造函数中调用

我从ReSharper收到一条关于从我的对象构造函数调用虚拟成员的警告.

为什么不做这件事?

c# resharper constructor warnings virtual-functions

1270
推荐指数
11
解决办法
17万
查看次数

EF codefirst:我应该初始化导航属性吗?

我曾经看过一些书(例如编程实体框架代码Julia Lerman)定义了他们的域类(POCO)而没有初始化导航属性,如:

public class User
{
    public int Id { get; set; }
    public string UserName { get; set; }

    public virtual ICollection<Address> Address { get; set; }
    public virtual License License { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

生成POCO时,其他一些书籍或工具(例如Entity Framework Power Tools)初始化类的导航属性,如:

public class User
{
    public User()
    {
        this.Addresses = new IList<Address>();
        this.License = new License();
    }
    public int Id { get; set; }
    public string UserName { get; set; }

    public virtual ICollection<Address> Addresses { …
Run Code Online (Sandbox Code Playgroud)

c# domain-driven-design entity-framework navigation-properties ef-code-first

59
推荐指数
2
解决办法
2万
查看次数

变更跟踪如何在Entity Framework中运行

鉴于以下代码,EF/DbContext如何了解对客户对象所做的更改:

class Program
{
    static void Main()
    {
        using(var shopContext = new ShopContext())
        {
            var customer = shopContext.Customers.Find(7);

            customer.City = "Marion";

            customer.State = "Indiana";

            shopContext.SaveChanges();
        }
    }
}

public class ShopContext : DbContext
{
    public DbSet<Customer> Customers { get; set; }
}

public class Customer
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string City { get; set; }
    public string State { …
Run Code Online (Sandbox Code Playgroud)

c# change-tracking entity-framework-4 dbcontext

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