实体框架隐藏继承的成员警告 [英] Entity Framework hides inherited member Warning

查看:112
本文介绍了实体框架隐藏继承的成员警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有产品示例和ProductDetail表。 Model Product是ProductDetail的基类。 ProductDetail中有一个ProductName。一切都正常,但我想知道为什么EF给我这个警告,以及如何去除这个。我尝试使用新的关键字更新Designer.cs,只是想看看会发生什么,但一旦编译就会将其删除。



将其删除,但没有找到任何相关信息。所以在这里问一个问题,如果有人知道如何处理这个警告。



我得到的警告在这里:

  DataLayer.ProductDetail.ProductName隐藏继承的成员
'Product.ProductName'。如果希望隐藏,请使用新的关键字。


解决方案

这是通用的C#警告。如果您有一个基类与子类中具有相同名称的成员,您将收到此警告。它基本上告诉你要小心,因为ProductName可能不会引用你的期望。



在这种特殊情况下,如果在ProductDetail上设置ProductName,则ProductName产品类将设置。根据您的映射,这可能是或可能不是一个问题。



Erick


I have For Example Product and a ProductDetail Table. Where in Model Product is a base class for ProductDetail. There is a ProductName in ProductDetail. Everything is working fine but I wanted to know that why the EF is giving me this warning and how to remove this. I tried updating Designer.cs with a new keyword was just keen to see what happens but it removes it as soon as it is compiled.

Googled it out but did not find any relevant information. So m here asking a question if anybody knows how to deal with this warning.

The Warning which I get is here:

  DataLayer.ProductDetail.ProductName' hides inherited member
 'Product.ProductName'. Use the new keyword if hiding was intended.     

解决方案

This is generic C# warning. If you have a base class that has a member with the same name as one in the child class, you will get this warning. It is basically telling you to be careful, as ProductName might not refer to what you expect.

In this particular case, if you set ProductName on ProductDetail, then the ProductName on the Product class will not be set. Depending on your mapping, this may or may not be an issue.

Erick

这篇关于实体框架隐藏继承的成员警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆