OneToManyAttribue with multiple foreign keys

Jan 5 at 5:06 PM
Hi.

I am trying to understand how the one to many attribute works.

I have an entity that links to another entity more than once on TWO foreign keys. If I just want to link one foriegn key I can just do the following:-

Child Entity

[EntityRef(FKParentId)]
IParentEntity Parent {get; set;}

Parent Entity

IList<IChildEntity> children {get; set;}

This works fine. But I want to link to the same parent on two seperate keys.

I have tried the following:-

Child Entity

[EntityRef(FKParentId1)]
IParentEntity Parent1 {get; set;}

[EntityRef(FKParentId2)]
IParentEntity Parent2 {get; set;}

Parent Entity

IList<IChildEntity> children1 {get; set;}
IList<IChildEntity> children2 {get; set;}

But this just throws a generic failed to build entity model error on Init() with no detail.

If I try and decorate the parent with a one to many attribute thus:-

[OneToMany("Parent1")]
IList<IChildEntity> children1 {get; set;}

[OneToMany("Parent2")]
IList<IChildEntity> children2 {get; set;}

I get a null reference exception on Init()

Even if I just have a single child reference e.g delete children2 I still get a null reference error.

Can anyone tell me where I'm going wrong?

P.S. I know having two foreign keys pointing to the same parent is fairly poor db / architectural design but I have no control over this and am unable to change the database schema at this point.

Regards,

Richard Lloyd.