为什么我需要在c#类中使用虚拟修饰符?
发布时间:2020-12-15 06:57:01 所属栏目:百科 来源:网络整理
导读:我有以下类: 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 Des
我有以下类:
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动态创建派生类. 只是为了让你的抽象类动态变成这样的想法: 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 } } } 您可以在调试时轻松看到这一点,您的EF类的实际实例类型具有非常奇怪的名称,因为它们是快速生成的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |