Nullable Foreign Key Error in Entity Framework

entity-framework nullable

Question

I have a table for my website that has a foreign key to a table for my clients. A Website may not always be connected with a Client, yet if I save a Website without naming a client, it fails with the error "Website." ClientID is a nullable int32 with the value 0.

I made an attempt to convert the connection in my EF diagram to an* next to Client and a 0..1 next to Website, however an error is then shown stating that ClientID cannot be nullable and hence cannot be set to 0..1. When I updated Website.ClientID to be nullable, the following problem appeared:

TothSolutions.msl(69,10) : error 3031: Problem in mapping fragments starting 
at line 69:Non-nullable column Website.ClientID in table Website is mapped to 
a nullable entity property.

How do I create a foreign key connection with a nullable dependant object?

1
0
4/24/2013 1:52:52 PM

Accepted Answer

I neglected to bring thenot null constraint off the database column.

0
4/24/2013 1:54:26 PM

Popular Answer

I had the same issue, but I was able to resolve it by deleting the table from my model and bringing it back in.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow