Using the Code First approach with Entity Framework 6.1.3
, I'm trying to create and configure my own many-to-many table based on this post. I strongly agree with him: I don't want to follow the conventions, because that limits my design.
Behold the many-to-many with payload class in Code First:
public class FooBar
{
[Key, Column(Order = 1)]
public virtual Foo Foo { get; set; }
[Key, Column(Order = 2)]
public virtual Bar Bar { get; set; }
//some more 'payload' properties
}
I'd like to keep it this way without adding the scalar properties. So I don't want these properties in my model:
public int FooId { get; set; }
public int BarId { get; set; }
My question is specifically if it's possible in Entity Framework 6 to have a navigation property like this as a (composite) key? Most answers to this question was based on earlier versions of Entity Framework, and it wasn't possible then. So the question is, is it possible now?
In this answer it's mentioned that:
You need to setup your classes in a specific way so that EF recognises what your trying to achieve.
But it's still unclear to me if it's technically possible. And if yes, could someone provide a sample in code on how to achieve this?