Entity Framework One to Zero One Link Link Mapping

I have client and address classes, as you see in the image below. enter image description here

I am trying to make one null relationship between these two tables. Entity Framework makes it work fine, but it will not use my property as a reference key. In this case, it is "ShippingAddressId". Instead, it creates ShippingAddress_Id. I have no problem with this. My problem is EF, not allowing me to map either property. I use the link key property in my business logic. Is there a way to map a foreign key field to a property in the case of one to one? I looked and found that you can do this if your relationship is one for many, saying HasForeignKey (x => x.ForeignKeyProperty). Why does EF not allow you to use the same one from scratch? Is there any other way to do this?

Someone asked a similar question , but he does not answer exactly what I want.

+5
source share

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


All Articles