2

Given entities like these:

public class Entity { public int Id { get; set; } public ICollection<EntityTwo> EntityTwos { get; set; } } public class EntityTwo { public int Id { get; set; } public int TypeId { get; set; } public int EntityId { get; set; } } 

Normally, Entity.EntityTwos would return all EntityTwo entities where EntityId equals Entity.Id. Is it possible to rig up the model so that property returns entities that join on that Id, but also have EntityTwo.TypeId == 2 (essentially adding a where clause to the join)?

2 Answers 2

1

You would have to do a manual join rather than relying on the navigational properties to create an implied join.

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you can solve this by thinking about it a different way. Your join keys would be:

{ TypeId, Id } equals { 2, Id } 

Maybe it's possible to use a constant as one of the two composite keys? See Ladislav's composite key as foreign key answer.

1 Comment

Seemed promising, but the composite mapping requires two properties (adding a property on the entity with a constant value didn't work either). This similar question/answer seems to confirm: stackoverflow.com/questions/11526497/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.