EF4 Code-First: include or not include foreign keys in the model when creating an association

In some Code-First EF4 walkthroughs, you see this pattern when defining POCOs:

public class Product
{
    public int ID { get; set; }

    public int ManufacturerId { get; set; }
    public virtual Manufacturer Manufacturer { get; set; }
}

Why should the product have both a Manufacturer and a link to the manufacturer? Does this have anything to do with lazy loading?

+3
source share
1 answer

Entity Framework: EF1 , , FK (, ManufacturerId) (, ), (, ). EF4 : , FK , .

, - , EF1 (.. ):

public class Product {
    public int ID { get; set; }
    public virtual Manufacturer Manufacturer { get; set; }
}

, , :

public class Product {
    public int ID { get; set; }
    public int ManufacturerId { get; set; }
    public virtual Manufacturer Manufacturer { get; set; }
}

, , EF- ManufacturerId FK Manufacturer , , .

, , FK , , .

+2

Source: https://habr.com/ru/post/1778617/


All Articles