public List <RelationDefinition> GetM2MRelations(bool withDisabled) { List <RelationDefinition> l = new List <RelationDefinition>(); foreach (RelationDefinitionBase rel in _model.GetRelations()) { RelationDefinition match = rel as RelationDefinition; if (match != null && (match.IsEntityTakePart(this)) && (!match.Disabled || withDisabled)) { l.Add(match); } } Dictionary <string, int> relationUniques = new Dictionary <string, int>(); FillUniqueRelations(l, relationUniques); if (BaseEntity != null) { var baseEntityRealation = from r in BaseEntity.GetM2MRelations(withDisabled) where !l.Contains(r) select r; FillUniqueRelations(baseEntityRealation, relationUniques); } foreach (var relationUnique in relationUniques) { if (relationUnique.Value > 1) { throw new WXMLException("Существуют дублирующиеся M2M связи." + relationUnique.Key); } } return(l); }
public void TestFillModel() { MSSQLProvider p = new MSSQLProvider(GetTestDB(), null); SourceView sv = p.GetSourceView(null, "ent1,ent2,1to2"); WXMLModel model = new WXMLModel(); SourceToModelConnector c = new SourceToModelConnector(sv, model); c.ApplySourceViewToModel(); Assert.AreEqual(3, model.GetSourceFragments().Count()); Assert.AreEqual(2, model.GetEntities().Count()); Assert.IsNotNull(model.GetEntity("e_dbo_ent1")); Assert.IsNotNull(model.GetEntity("e_dbo_ent2")); Assert.AreEqual(1, model.GetEntity("e_dbo_ent1").GetProperties().Count()); Assert.AreEqual(1, model.GetEntity("e_dbo_ent1").GetPkProperties().Count()); Assert.IsTrue(model.GetEntity("e_dbo_ent1").GetPkProperties().First().HasAttribute(Field2DbRelations.PrimaryKey)); Assert.AreEqual(2, model.GetEntity("e_dbo_ent2").GetProperties().Count()); Assert.AreEqual(1, model.GetRelations().Count()); }