我有以下类:
public class Delivery { // Primary key,and one-to-many relation with Customer public int DeliveryID { get; set; } public virtual int CustomerID { get; set; } public virtual Customer Customer { get; set; } // Properties string Description { get; set; } }
有人可以解释为什么客户信息用虚拟编码.这是什么意思?
解决方法
猜猜你在使用EF.
当您制作NavigationProperty虚拟机时,会发生什么是EF动态创建派生类.
该类实现了允许延迟加载和其他任务的功能,例如维护EF为您执行的关系.
只是为了让你的抽象类动态变成这样的想法:
public class DynamicEFDelivery : Delivery { public override Customer Customer { get { return // go to the DB and actually get the customer } set { // attach the given customer to the current entity within the current context // afterwards set the Property value } } }