开发者

Entity Framework: Problem associating entities with nullable field

I'm using Entity Framework, and I'm tr开发者_StackOverflowying to associate an entity that was created from a database table with an entity that was created from a database view. Because Entity Framework is not able to infer the relationships between a database table and a view automatically, I'm using the entity designer to construct an "association" between the entities. However, if the foreign key is a nullalbe type, I get the following error:

Error 113: Multiplicity is not valid in Role 'Company' in relationship 'UsersView'. Because all the properties in the Dependent Role are nullable, multiplicity of the Principal Role must be '0..1'.

In my scenario, I have a CompanyId foreign key in my UsersView that's nullable (i.e. users may not have a company). Creating an association with a nullable foreign key was never a problem with Linq 2 SQL. Does anyone know how I can get around this problem in Entity Framework?

Thanks in advance.


I think you should be able to select the Association, and set the Multiplicity setting in the Properties pane to 0..1. That should resolve the error.


I'm posting this because I ran into the same error manually creating an association in the model designer in Visual Studio 2010. My field didn't allow nulls in the database but for some reason in the designer the Nullable property for that field was set to (None) instead of True. It took me a while to figure out why the designer was complaining. Once I manually changed the Nullable property of field I was trying to create an association to it without any errors.

I know this doesn't answer the original question but I found this post trying to solve my issue which was giving the same error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜