本文整理汇总了C#中ModelBuilder.AddIdentity方法的典型用法代码示例。如果您正苦于以下问题:C# ModelBuilder.AddIdentity方法的具体用法?C# ModelBuilder.AddIdentity怎么用?C# ModelBuilder.AddIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelBuilder
的用法示例。
在下文中一共展示了ModelBuilder.AddIdentity方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModelBuilder
void IDomainChangeListener.BeforeSave(EntityModel entityModel)
{
if (!entityModel.Properties.Contains("Id"))
{
ModelBuilder mb = new ModelBuilder(entityModel);
mb.AddIdentity("Id");
}
}
示例2: Test_DomainModelSerializer
public void Test_DomainModelSerializer()
{
var dm = new DomainModel();
ModelBuilder ba = new ModelBuilder("Author");
ba.AddIdentity("Id");
ba.AddString("FirstName", 128);
ba.AddString("LastName", 128);
ba.AddComputed("FullName", "[LastName]+N', '+[FirstName]");
ba.AddBoolean("IsAlive", true);
ba.AddInteger("NumberOfAwards");
ba.AddDateTime("Born");
ba.AddDecimal("Rating");
ba.EntityModel.Rules.Add(new FutureOrPastDateRuleModel((DateTimePropertyModel)ba.EntityModel.Properties["born"], TimeSpan.Zero, false));
ModelBuilder bb = new ModelBuilder("Book");
bb.AddIdentity("Id");
bb.AddString("Title", 256);
bb.AddString("ISBN", 20);
bb.AddDecimal("Price");
bb.AddEnum<Genre>("Genre");
bb.AddUri("BookUri", "books");
bb.Rules.AddRequired("title");
bb.Rules.AddUnique("ISBN");
ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");
dm.Entities.Add(ba.EntityModel);
dm.Entities.Add(bb.EntityModel);
dm.Relations.Add(ba.EntityModel.Relations.Single());
ModelBuilder mbRel = new ModelBuilder(ba.EntityModel.Relations.Single());
mbRel.AddIdentity("id");
mbRel.AddIdentity("rid");
mbRel.AddIdentity("lid");
mbRel.Rules.AddRequired("lid");
mbRel.Rules.AddRequired("rid");
DomainModelSerializer ser = new DomainModelSerializer();
XmlDocument xmlDoc = ser.Serialize(dm);
var dm2 = ser.Deserialize(xmlDoc);
Assert.AreEqual(dm.Entities.Count, dm2.Entities.Count);
Assert.AreEqual(dm.Relations.Count, dm2.Relations.Count);
var en1 = dm.Entities.GetEnumerator();
var en2 = dm2.Entities.GetEnumerator();
while (en1.MoveNext() && en2.MoveNext())
{
Assert.AreEqual(en1.Current.Name, en2.Current.Name);
Assert.AreEqual(en1.Current.Properties.Count, en2.Current.Properties.Count);
Assert.AreEqual(en1.Current.Relations.Count, en2.Current.Relations.Count);
Assert.AreEqual(en1.Current.Rules.Count, en2.Current.Rules.Count);
var p1 = en1.Current.Properties.GetEnumerator();
var p2 = en2.Current.Properties.GetEnumerator();
while (p1.MoveNext() && p2.MoveNext())
{
Assert.AreEqual(p1.Current.Name, p2.Current.Name);
Assert.AreEqual(p1.Current.Type, p2.Current.Type);
Assert.AreEqual(p1.Current.DefaultValue, p2.Current.DefaultValue);
Assert.AreEqual(p1.Current.GetType(), p2.Current.GetType());
if (p1.Current.Type == PropertyType.Enum)
Assert.AreEqual(((EnumPropertyModel)p1.Current).EnumType, ((EnumPropertyModel)p2.Current).EnumType);
else if (p1.Current.Type == PropertyType.Computed)
Assert.AreEqual(((ComputedPropertyModel)p1.Current).Formula, ((ComputedPropertyModel)p2.Current).Formula);
else if (p1.Current.Type == PropertyType.Number)
Assert.AreEqual(((NumberPropertyModel)p1.Current).IsInteger, ((NumberPropertyModel)p2.Current).IsInteger);
else if (p1.Current.Type == PropertyType.Sequence)
{
Assert.AreEqual(((SequencePropertyModel)p1.Current).SequenceType, ((SequencePropertyModel)p2.Current).SequenceType);
Assert.AreEqual(((SequencePropertyModel)p1.Current).SequenceId, ((SequencePropertyModel)p2.Current).SequenceId);
}
}
var r1 = en1.Current.Rules.GetEnumerator();
var r2 = en2.Current.Rules.GetEnumerator();
while (r1.MoveNext() && r2.MoveNext())
{
Assert.AreEqual(r1.Current.GetType(), r2.Current.GetType());
if (r1.Current is RequiredRuleModel)
Assert.AreEqual((r1.Current as RequiredRuleModel).Property.Name, (r2.Current as RequiredRuleModel).Property.Name);
else if (r1.Current is UniqueRuleModel)
{
Assert.AreEqual((r1.Current as UniqueRuleModel).Properties.Count(), (r2.Current as UniqueRuleModel).Properties.Count());
var pren1 = (r1.Current as UniqueRuleModel).Properties.GetEnumerator();
var pren2 = (r2.Current as UniqueRuleModel).Properties.GetEnumerator();
while (pren1.MoveNext() && pren2.MoveNext())
{
Assert.AreEqual(pren1.Current.Name, pren2.Current.Name);
}
}
else if (r1.Current is FutureOrPastDateRuleModel)
{
var er1 = r1.Current as FutureOrPastDateRuleModel;
var er2 = r2.Current as FutureOrPastDateRuleModel;
Assert.AreEqual(er1.Future, er2.Future);
Assert.AreEqual(er1.Offset, er2.Offset);
Assert.AreEqual(er1.Property.Name, er2.Property.Name);
}
}
}
//.........这里部分代码省略.........
示例3: CreateDomain
private static void CreateDomain()
{
var dm = new DomainModel();
ModelBuilder ba = new ModelBuilder("Author");
ba.AddIdentity("Id");
ba.AddString("FirstName", 128);
ba.AddString("LastName", 128);
ba.AddBoolean("IsAlive", true);
ba.AddInteger("NumberOfAwards");
ba.AddDateTime("Born");
ba.AddDecimal("Rating");
ModelBuilder bb = new ModelBuilder("Book");
bb.AddIdentity("Id");
bb.AddString("Title", 256);
bb.AddString("ISBN", 20);
bb.AddDecimal("Price");
bb.AddEnum<Genre>("Genre");
bb.Rules.AddRequired("title");
bb.Rules.AddUnique("ISBN");
ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");
dm.Entities.Add(ba.EntityModel);
dm.Entities.Add(bb.EntityModel);
ModelBuilder bo = new ModelBuilder("Order");
bo.AddDecimal("Total");
bo.AddBoolean("Paid");
bo.AddDateTime("CreatedOn");
bo.AddDateTime("ShipmentDate");
bo.AddRelationTo(dm.Entities["book"], RelationType.ManyToMany, "Ordered");
dm.Entities.Add(bo.EntityModel);
dms.Save(dm);
}
示例4: Test_DomainModelService_Union
public void Test_DomainModelService_Union()
{
var dm = new DomainModel();
ModelBuilder ba = new ModelBuilder("Author");
ba.AddIdentity("Id");
ba.AddString("FirstName", 128);
ba.AddString("LastName", 128);
ba.AddComputed("FullName", "[LastName]+N', '+[FirstName]");
ba.AddBoolean("IsAlive", true);
ba.AddInteger("NumberOfAwards");
ba.AddDateTime("Born");
ba.AddDecimal("Rating");
ModelBuilder bb = new ModelBuilder("Book");
bb.AddIdentity("Id");
bb.AddString("Title", 256);
bb.AddString("ISBN", 20);
bb.Rules.AddRequired("title");
bb.Rules.AddUnique("ISBN");
ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");
dm.Entities.Add(ba.EntityModel);
dm.Entities.Add(bb.EntityModel);
ModelBuilder bo = new ModelBuilder("Order");
bo.AddDecimal("Total");
bo.AddBoolean("Paid");
bo.AddDateTime("CreatedOn");
bo.AddDateTime("ShipmentDate");
ModelBuilder bb2 = new ModelBuilder("Book");
bb2.AddIdentity("Id");
bb2.AddString("Title", 256);
bb2.AddString("Barcode", 20);
bb2.AddDecimal("Price");
bo.AddRelationTo(bb2.EntityModel, RelationType.ManyToMany, "Ordered");
var dm2 = new DomainModel();
dm2.Entities.Add(bo.EntityModel);
dm2.Entities.Add(bb2.EntityModel);
var un = svc.Union(new DomainModel[] { dm, dm2 });
Assert.AreEqual(3, un.Entities.Count);
var author = un.Entities["author"];
Assert.AreEqual(8, author.Properties.Count);
Assert.AreEqual(5, un.Entities["book"].Properties.Count);
Assert.AreEqual(4, un.Entities["Order"].Properties.Count);
Assert.AreEqual(2, un.Relations.Count);
}
示例5: Test_DomainModelService_Merge
public void Test_DomainModelService_Merge()
{
var dm = new DomainModel();
ModelBuilder ba = new ModelBuilder("Author");
ba.AddIdentity("Id");
ba.AddString("FirstName", 128);
ba.AddString("LastName", 128);
ba.AddComputed("FullName", "[LastName]+N', '+[FirstName]");
ba.AddBoolean("IsAlive", true);
ba.AddInteger("NumberOfAwards");
ba.AddDateTime("Born");
ba.AddDecimal("Rating");
ModelBuilder bb = new ModelBuilder("Book");
bb.AddIdentity("Id");
bb.AddString("Title", 256);
bb.AddString("ISBN", 20);
bb.AddDecimal("Price");
bb.AddEnum<Genre>("Genre", Genre.Fantasy);
bb.Rules.AddRequired("title");
bb.Rules.AddUnique("ISBN");
ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");
dm.Entities.Add(ba.EntityModel);
dm.Entities.Add(bb.EntityModel);
svc.Save(dm);
using (var conn = new TestDatabaseService().GetSqlConnection())
{
conn.Open();
DatabaseManager dbm = new DatabaseManager(conn);
dbm.LoadSchema();
var tableA = dbm.Tables.Find(t => t.Name == "Author");
Assert.IsNotNull(tableA);
var fnCol = tableA.Columns.Find(c => c.Name.Equals("FullName", StringComparison.InvariantCultureIgnoreCase));
Assert.IsNotNull(fnCol);
}
ModelBuilder bo = new ModelBuilder("Order");
bo.AddDecimal("Total");
bo.AddBoolean("Paid");
bo.AddDateTime("CreatedOn");
bo.AddDateTime("ShipmentDate");
bo.AddRelationTo(dm.Entities["book"], RelationType.ManyToMany, "Ordered");
dm.Entities.Add(bo.EntityModel);
ba.EntityModel.Properties.Remove(ba.EntityModel.Properties["IsAlive"]);
(ba.EntityModel.Properties["LastName"] as StringPropertyModel).Length = 256;
(ba.EntityModel.Properties["firstName"] as StringPropertyModel).Length = 256;
(bb.EntityModel.Properties["genre"] as EnumPropertyModel).DefaultValue = Genre.Horror;
ba.AddString("Nickname", 256);
svc.Merge(dm);
Assert.AreEqual(3, svc.Domain.Entities.Count);
//foreach (var em1 in dm.Entities)
//{
// var em2 = svc.Domain.Entities[em1.Name];
// Assert.AreEqual(em1.Properties.Count, em2.Properties.Count);
//}
//TODO-tests:finish domainmodelservice_merge test
//Computed columns are droped and recreated when upgrading the columns in their computed definition
using (var conn = new TestDatabaseService().GetSqlConnection())
{
conn.Open();
DatabaseManager dbm = new DatabaseManager(conn);
dbm.LoadSchema();
var tableA = dbm.Tables.Find(t => t.Name == "Author");
Assert.IsNotNull(tableA);
var fnCol = tableA.Columns.Find(c => c.Name.Equals("FullName", StringComparison.InvariantCultureIgnoreCase));
Assert.IsNotNull(fnCol);
}
}
示例6: Test_DomainModelService_Compare
public void Test_DomainModelService_Compare()
{
var dm = new DomainModel();
ModelBuilder ba = new ModelBuilder("Author");
ba.AddIdentity("Id");
ba.AddString("FirstName", 128);
ba.AddString("LastName", 128);
ba.AddComputed("FullName", "[LastName]+N', '+[FirstName]");
ba.AddBoolean("IsAlive", false);
ba.AddInteger("NumberOfAwards");
ba.AddDateTime("Born");
ba.AddDecimal("Rating");
ba.AddString("Uri", 20);
ModelBuilder bb = new ModelBuilder("Book");
bb.AddIdentity("Id");
bb.AddString("Title", 256);
bb.AddString("ISBN", 20);
bb.AddDecimal("Price");
bb.Rules.AddUnique("ISBN");
bb.Rules.AddRequired("title");
ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");
dm.Entities.Add(ba.EntityModel);
dm.Entities.Add(bb.EntityModel);
svc.Save(dm);
ModelBuilder bo = new ModelBuilder("Order");
bo.AddIdentity("Number");
bo.AddDecimal("Total");
bo.AddBoolean("Paid");
bo.AddDateTime("CreatedOn");
bo.AddDateTime("ShipmentDate");
bo.AddRelationTo(dm.Entities["book"], RelationType.ManyToMany, "Ordered");
dm.Entities.Add(bo.EntityModel);
ba.EntityModel.Properties.Remove(ba.EntityModel.Properties["IsAlive"]);
(ba.EntityModel.Properties["LastName"] as StringPropertyModel).Length = 256;
(ba.EntityModel.Properties["firstName"] as StringPropertyModel).Length = 256;
ba.AddString("Nickname", 256);
ba.Rules.AddUnique("Uri");
(ba.EntityModel.Properties["Rating"] as NumberPropertyModel).DefaultValue = 5.0m;
DomainModelChanges dmc = svc.CompareWithExisting(dm);
Assert.AreEqual(2, dmc.EntityChanges.Count());
Assert.AreEqual(1, dmc.EntityChanges.Count(ec => ec.Change == ChangeType.Created));
var ecs = dmc.EntityChanges.Single(ec => ec.Change == ChangeType.Created);
Assert.AreEqual(bo.EntityModel.Properties.Count, ecs.PropertyChanges.Count());
Assert.AreEqual(1, dmc.EntityChanges.Count(ec => ec.Change == ChangeType.Modified));
Assert.AreEqual(1, dmc.RelationChanges.Count());
var change = dmc.EntityChanges.Single(e => e.New.Name == ba.EntityModel.Name);
Assert.AreEqual(5, change.PropertyChanges.Count());
Assert.AreEqual(3, change.PropertyChanges.Count(pc => pc.Change == ChangeType.Modified));
Assert.AreEqual(1, change.PropertyChanges.Count(pc => pc.Change == ChangeType.Deleted));
Assert.AreEqual(1, change.PropertyChanges.Count(pc => pc.Change == ChangeType.Created));
Assert.AreEqual(1, change.RuleChanges.Count());
}
示例7: Test_DomainModelService_Basic
public void Test_DomainModelService_Basic()
{
var dm = new DomainModel();
ModelBuilder ba = new ModelBuilder("Author");
ba.AddIdentity("Id");
ba.AddString("FirstName", 128);
ba.AddString("LastName", 128);
ba.AddComputed("FullName", "[LastName]+N', '+[FirstName]");
ba.AddBoolean("IsAlive", true);
ba.AddInteger("NumberOfAwards");
ba.AddDateTime("Born");
ba.AddDecimal("Rating");
ba.EntityModel.Rules.Add(new FutureOrPastDateRuleModel((DateTimePropertyModel)ba.EntityModel.Properties["born"], TimeSpan.Zero, false));
ModelBuilder bb = new ModelBuilder("Book");
bb.AddIdentity("Id");
bb.AddString("Title", 256);
bb.AddString("ISBN", 20);
bb.AddDecimal("Price");
bb.AddEnum<Genre>("Genre");
bb.Rules.AddRequired("title");
bb.Rules.AddUnique("ISBN");
ba.AddRelationTo(bb.EntityModel, RelationType.OneToMany, "Author");
dm.Entities.Add(ba.EntityModel);
dm.Entities.Add(bb.EntityModel);
svc.Save(dm);
Assert.IsNotNull(svc.Domain);
Assert.IsNotNull(svc.Domain.Entities["author"]);
Assert.IsNotNull(svc.Domain.Entities["book"]);
Assert.IsNotNull(svc.Domain.Relations["book", "author", "author"]);
}