I have 2 models.
Model Foo
[System.Data.Linq.Mapping.Table(Name = ...)]
public class Foo
{
[System.Data.Linq.Mapping.Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int ID { get; set; }
[System.Data.Linq.Mapping.Column(IsPrimaryKey = true)]
public int BarID { get; set; }
// 1:1 association - foo <> bar
[System.Data.Linq.Mapping.Association(Name = "FK_Foo_Bar", Storage = "mBar", OtherKey = "ID", ThisKey = "BarID")]
public Bar CurrentRevision
{
get { return mBar.Entity; }
set { mBar.Entity = value; }
}
private System.Data.Linq.EntityRef<Bar> mBar = new System.Data.Linq.EntityRef<Bar>();
}
Model Bar
[System.Data.Linq.Mapping.Table(Name = ...)]
public class Bar
{
[System.Data.Linq.Mapping.Column(IsPrimaryKey = true, IsDbGenerated = true)]
public int ID { get; set; }
[System.Data.Linq.Mapping.Column(IsPrimaryKey = true)]
public int FooID { get; set; }
// 1:1 association - bar <> foo
[System.Data.Linq.Mapping.Association(Name = "FK_Bar_Foo", Storage = "mFoo", OtherKey = "ID", ThisKey = "FooID")]
public Foo Folder
{
get { return mFoo.Entity; }
set { mFoo.Entity = value; }
}
private System.Data.Linq.EntityRef<Foo> mFoo = new System.Data.Linq.EntityRef<Foo>();
}
I want to insert a Foo and a Bar like so
lFoo = new Foo();
DataContext.Foos.InsertOnSubmit(lFoo);
lBar = new Bar();
DataContext.Bars.InsertOnSubmit(lBar);
lBar.Foo = lFoo; // link foo to bar
lFoo.Bar = lBar; // link bar to foo
DataContext.SubmitChanges();
A row for lFoo
and a row for lBar
is added to the DB but the FooID
and BarID
field remains zero.
Is there a way to let the framework update column FooID
and BarID
with the correct IDs automatically instead of doing this manually?