Skip to content
Advertisement

A problem with the foreign key using Entity-Framework

Im using Entity Framework and have this two classes:

And I instance a new Product like this:

When I add and save this object, does not record it in the database, but if I instance the product with a NULL value in the Client attribute, does appear but with that NULL value. I dont know why this is happening…

Advertisement

Answer

Assuming you have One-to-Many relationship between Client and Product your code should look like this :

and then

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement