Entity Framework hides inherited member Warning

2019-07-08 09:32发布

问题:

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.     

回答1:

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