I seem to remember (perhaps incorrectly) that DLinq offered automatic associations. I can't seem to find how to enable or accomplish this in EF.
Example:
public partial class Person
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Clan Clan { get; set; }
}
public partial class Clan
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Person> People { get; set; }
}
If these were my entities, then I would like to perform an action like this:
var p = new Person() { Name = "Tom" };
var c = new Clan() { Name = "SomeClan" };
p.Clan = c;
ASSERT( c.People.First() == p )
or alternately
var p = new Person() { Name = "Tom" };
var c = new Clan() { Name = "SomeClan" };
c.People.Add(p);
ASSERT( p.Clan == c )
Further, should I have used the c.People.Add
method, it should have checked to see if p.Clan
already references a different Clan, and if so, removes it from that clan's People collection.
In DLINQ, I believed they used EntitySet and EntityRef to accomplish this. Does an equivalent exist in Entity Framework?
Many thanks!