本文整理汇总了C#中FixupContext.Add方法的典型用法代码示例。如果您正苦于以下问题:C# FixupContext.Add方法的具体用法?C# FixupContext.Add怎么用?C# FixupContext.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FixupContext
的用法示例。
在下文中一共展示了FixupContext.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Navigation_fixup_is_non_destructive_to_existing_graphs
public void Navigation_fixup_is_non_destructive_to_existing_graphs()
{
using (var context = new FixupContext())
{
var category11 = new Category { Id = 11 };
var category12 = new Category { Id = 12 };
var category13 = new Category { Id = 13 };
var product21 = new Product { Id = 21, CategoryId = 11, Category = category11 };
var product22 = new Product { Id = 22, CategoryId = 11, Category = category11 };
var product23 = new Product { Id = 23, CategoryId = 11, Category = category11 };
var product24 = new Product { Id = 24, CategoryId = 12, Category = category12 };
var product25 = new Product { Id = 25, CategoryId = 12, Category = category12 };
category11.Products.Add(product21);
category11.Products.Add(product22);
category11.Products.Add(product23);
category12.Products.Add(product24);
category12.Products.Add(product25);
var specialOffer31 = new SpecialOffer { Id = 31, ProductId = 22, Product = product22 };
var specialOffer32 = new SpecialOffer { Id = 32, ProductId = 22, Product = product22 };
var specialOffer33 = new SpecialOffer { Id = 33, ProductId = 24, Product = product24 };
var specialOffer34 = new SpecialOffer { Id = 34, ProductId = 24, Product = product24 };
var specialOffer35 = new SpecialOffer { Id = 35, ProductId = 24, Product = product24 };
product22.SpecialOffers.Add(specialOffer31);
product22.SpecialOffers.Add(specialOffer32);
product24.SpecialOffers.Add(specialOffer33);
product24.SpecialOffers.Add(specialOffer34);
product24.SpecialOffers.Add(specialOffer35);
context.Add(category11);
AssertAllFixedUp(context);
context.Add(category12);
AssertAllFixedUp(context);
context.Add(category13);
AssertAllFixedUp(context);
context.Add(product21);
AssertAllFixedUp(context);
context.Add(product22);
AssertAllFixedUp(context);
context.Add(product23);
AssertAllFixedUp(context);
context.Add(product24);
AssertAllFixedUp(context);
context.Add(product25);
AssertAllFixedUp(context);
context.Add(specialOffer31);
AssertAllFixedUp(context);
context.Add(specialOffer32);
AssertAllFixedUp(context);
context.Add(specialOffer33);
AssertAllFixedUp(context);
context.Add(specialOffer34);
AssertAllFixedUp(context);
context.Add(specialOffer35);
AssertAllFixedUp(context);
Assert.Equal(3, category11.Products.Count);
Assert.Equal(2, category12.Products.Count);
Assert.Equal(0, category13.Products.Count);
Assert.Equal(0, product21.SpecialOffers.Count);
Assert.Equal(2, product22.SpecialOffers.Count);
Assert.Equal(0, product23.SpecialOffers.Count);
Assert.Equal(3, product24.SpecialOffers.Count);
Assert.Equal(0, product25.SpecialOffers.Count);
Assert.Equal(3, context.ChangeTracker.Entries<Category>().Count());
Assert.Equal(5, context.ChangeTracker.Entries<Product>().Count());
Assert.Equal(5, context.ChangeTracker.Entries<SpecialOffer>().Count());
}
}
示例2: Navigation_fixup_happens_when_new_entities_are_tracked
public void Navigation_fixup_happens_when_new_entities_are_tracked()
{
using (var context = new FixupContext())
{
context.Add(new Category { Id = 11 });
context.Add(new Category { Id = 12 });
context.Add(new Category { Id = 13 });
context.Add(new Product { Id = 21, CategoryId = 11 });
AssertAllFixedUp(context);
context.Add(new Product { Id = 22, CategoryId = 11 });
AssertAllFixedUp(context);
context.Add(new Product { Id = 23, CategoryId = 11 });
AssertAllFixedUp(context);
context.Add(new Product { Id = 24, CategoryId = 12 });
AssertAllFixedUp(context);
context.Add(new Product { Id = 25, CategoryId = 12 });
AssertAllFixedUp(context);
context.Add(new SpecialOffer { Id = 31, ProductId = 22 });
AssertAllFixedUp(context);
context.Add(new SpecialOffer { Id = 32, ProductId = 22 });
AssertAllFixedUp(context);
context.Add(new SpecialOffer { Id = 33, ProductId = 24 });
AssertAllFixedUp(context);
context.Add(new SpecialOffer { Id = 34, ProductId = 24 });
AssertAllFixedUp(context);
context.Add(new SpecialOffer { Id = 35, ProductId = 24 });
AssertAllFixedUp(context);
Assert.Equal(3, context.ChangeTracker.Entries<Category>().Count());
Assert.Equal(5, context.ChangeTracker.Entries<Product>().Count());
Assert.Equal(5, context.ChangeTracker.Entries<SpecialOffer>().Count());
}
}