本文整理汇总了C#中Relation.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# Relation.SetData方法的具体用法?C# Relation.SetData怎么用?C# Relation.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Relation
的用法示例。
在下文中一共展示了Relation.SetData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_EntityRepo_AttachDetach
public void Test_EntityRepo_AttachDetach()
{
var dbService = new TestDatabaseService();
var repository = new EntityRepository(dms, dbService, new SequenceProvider(dbService));
using (var ctx = dbService.GetDatabaseContext(true))
{
#region prepare data
var jordan = new Author()
{
FirstName = "Robert",
LastName = "Jordan",
IsAlive = false,
Born = new DateTime(1948, 10, 17),
Rating = 10.0m
};
var feist = new Author()
{
FirstName = "Raymond",
LastName = "Feist",
IsAlive = true,
Born = new DateTime(1963, 2, 14),
Rating = 6.7m
};
var fb1 = new Book()
{
Title = "The Apprentice",
Price = 19.90m
};
var fb2 = new Book()
{
Title = "The Magician",
Price = 17.10m
};
repository.Create(jordan);
repository.Create(feist);
repository.Create(fb1);
repository.Create(fb2);
#endregion
repository.Attach(feist, new Relation("author", fb1));
var rel2 = new Relation("author", fb2);
var writtenOn = new DateTime(1996, 4, 25);
rel2.SetData<DateTime>("WrittenOn", writtenOn);
repository.Attach(feist, rel2);
var q = new EntityQuery2("author", feist.Id);
q.AddProperties("FirstName", "lastname", "isalive", "born", "rating");
q.Include("book", "author");
var e = repository.Read(q);
Assert.AreEqual(2, e.GetManyRelations("book", "author").Count());
var bq = new EntityQuery2("book");
bq.Include("author", "author");
var bes = repository.Search(bq);
foreach (var be in bes)
{
Assert.AreEqual(1, be.RelationsData.Count);
Assert.AreEqual(feist.Id, be.GetSingleRelation("author", "author").Entity.Id);
if (be.Id == fb2.Id)
Assert.AreEqual(writtenOn, be.GetSingleRelation("author", "author").GetData<DateTime>("writtenon"));
}
repository.Detach(feist, new Relation("author", fb1));
e = repository.Read(q);
Assert.AreEqual(1, e.GetManyRelations("book", "author").Count());
repository.Attach(fb1, new Relation("author", feist));
e = repository.Read(q);
Assert.AreEqual(2, e.GetManyRelations("book", "author").Count());
repository.Detach(fb1, new Relation("author", feist));
e = repository.Read(q);
Assert.AreEqual(1, e.GetManyRelations("book", "author").Count());
bool ex = false;
try { repository.Attach(fb2, new Relation("author", jordan)); }
catch (Exception) { ex = true; }
Assert.IsTrue(ex, "Exception not thrown when attaching two authors to single book");
}
}