我使用Linq To Entities来获取 2 个对象 m1 和 m2。而且我不明白为什么 2 个不同的对象引用相同的模板表。
我怀疑是由于 MConfigOnPage1、MConfigOnPage2 与 MConfiguration 之间的连接所致。也许它应该以某种方式拆分?
我附上了我的 ERD 和代码。
我会很感激解释为什么会发生这种情况?
谢谢
var cxt = new Entities();
//this returns MConfiguration with Id=19
var m1 = (from mop in cxt.MConfigOnPage1
where mop.SiteMapId == 15 && mop.HolderId == 13
select mop.MConfiguration).FirstOrDefault();
//this returns MConfiguration with Id=40
var m2 = (from mop in cxt.MConfigOnPage2
where mop.SiteMapId == 15 && mop.HolderId == 1
select mop.MConfiguration).FirstOrDefault();
var t1 = m1.Holder.Template;
var t1.Code = 13;
var t2 = m2.Holder.Template;
//I expect that **t2.Code** to be 0, but it equals 13
//This behavior tells me that m1 & m2 reference the same Template object,
// BUT shouldn't m1 & m2 to have their own Template objects?
ERD
MConfiguration表数据
持有人表数据____________________________________________________________________________ 模板表数据
_____________________________________