Currently i am trying tomake a EF database and I wunder why and how to get this is "NULL" away from my table

3298 views asp.net-mvc
6

I am currently trying to make a EF system with a few relations/FKs.

My classes looklik this : I have an artikel class, a Location class and a prognoseclass that look like following: enter image description here

enter image description here

enter image description here

After i run my "Package manager comandline" with a "fresh database" i get with seeded data Like this:

enter image description here

Now the question is : why is there a "Entry" Location_LocationId that has a NULL valll?

How can one get this away or shall it be there:??

If I havent provided enough data please let me know.

My system is working as i want to have it but i am desperate trying to "optimize" it and trying to get questions like this cleared out.

answered question

1 Answer

11

Try to use attribute ForeignKey.

[ForeignKey("Location")]

before "LocationId" property in "Prognose" class

You can read this tutorial http://www.entityframeworktutorial.net/code-first/configure-one-to-one-relationship-in-code-first.aspx If you want to make one to one relations in EF.

posted this

Have an answer?

JD

Please login first before posting an answer.