in Dlinq there is really neat feature
something similar like mapping a "many-to-one" but thre can be used extra property for reference ID
// Example
So I have 2 classes
Code:
public class A
{
public int Id { get; set; }
public string Name { get; set; }
}
public class B
{
public int Id { get; set; }
public string Name { get; set; }
public A MappedA { get; set; } //this is many-to-one mapping
public int AId { get; set; } //this should be a id for inserted a
}
So I created little unit test for this
Code:
public void MapManyToOneAndPropertyUsesSameColumnFixture()
{
ISession s = OpenSession();
A a = new A {Name = "First"};
s.Save(a);
B b = new B {Name = "Second", AId = a.Id};
s.Save(b);
s.Flush();//This throws an System.IndexOutOfRangeException: Invalid index 3 for this SqlParameterCollection with Count=3.
s.Close();
s = OpenSession();
B newB = s.Get<B>(b.Id);
Assert.IsNull(b.MappedA);
s.Close();
}
So I think it would be nice to have this feature, althoug there is another way but I like the DLinq approach for this case.
Code:
A a = new A {Name = "First"};
s.Save(a);
B b = new B {Name = "Second", MappedA = session.Get<A>(a.Id)};
s.Save(b);