本文整理汇总了C#中EntityType.AddNavigation方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.AddNavigation方法的具体用法?C# EntityType.AddNavigation怎么用?C# EntityType.AddNavigation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.AddNavigation方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildModel
private static IModel BuildModel()
{
var model = new Model();
var builder = new ModelBuilder(model);
builder.Annotation("ModelAnnotation1", "ModelValue1");
builder.Annotation("ModelAnnotation2", "ModelValue2");
var entityType1 = new EntityType(typeof(KoolEntity1));
var property = entityType1.AddProperty("Id1", typeof(int));
entityType1.SetKey(property);
entityType1.AddProperty("Id2", typeof(Guid));
entityType1.AddProperty("KoolEntity2Id", typeof(int));
model.AddEntityType(entityType1);
var entityType2 = new EntityType(typeof(KoolEntity2));
entityType2.AddProperty("KoolEntity1Id1", typeof(int));
entityType2.AddProperty("KoolEntity1Id2", typeof(Guid));
entityType2.AddProperty("KoolEntity3Id", typeof(int));
model.AddEntityType(entityType2);
var entityType3 = new EntityType(typeof(KoolEntity3));
entityType3.AddProperty("KoolEntity4Id", typeof(int));
model.AddEntityType(entityType3);
var entityType4 = new EntityType(typeof(KoolEntity4));
model.AddEntityType(entityType4);
var entityType5 = new EntityType(typeof(KoolEntity5));
model.AddEntityType(entityType5);
var entityType6 = new EntityType(typeof(KoolEntity6));
entityType6.AddProperty("Kool5Id", typeof(int));
model.AddEntityType(entityType6);
for (var i = 7; i <= 20; i++)
{
var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);
Assert.NotNull(type);
model.AddEntityType(new EntityType(type));
}
for (var i = 2; i <= 20; i++)
{
var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);
var entityType = model.GetEntityType(type);
var id = entityType.AddProperty(entityType.Type.GetProperty("Id"));
entityType.SetKey(id);
}
for (var i = 1; i <= 20; i++)
{
var type = Type.GetType("Microsoft.Data.Entity.FunctionalTests.Metadata.KoolEntity" + i);
var entityType = model.GetEntityType(type);
entityType.Annotations.Add(new Annotation("Annotation1", "Value1"));
entityType.Annotations.Add(new Annotation("Annotation2", "Value2"));
var foo = entityType.AddProperty(entityType.Type.GetProperty("Foo" + i));
foo.Annotations.Add(new Annotation("Foo" + i + "Annotation1", "Foo" + i + "Value1"));
foo.Annotations.Add(new Annotation("Foo" + i + "Annotation2", "Foo" + i + "Value2"));
var goo = entityType.AddProperty(entityType.Type.GetProperty("Goo" + i));
}
var fk11 = entityType1.AddForeignKey(entityType2.GetKey(), new[] { entityType1.GetProperty("KoolEntity2Id") });
var fk21 = entityType2.AddForeignKey(entityType1.GetKey(), new[] { entityType2.GetProperty("KoolEntity1Id1") });
var fk22 = entityType2.AddForeignKey(entityType3.GetKey(), new[] { entityType2.GetProperty("KoolEntity3Id") });
var fk31 = entityType3.AddForeignKey(entityType4.GetKey(), new[] { entityType3.GetProperty("KoolEntity4Id") });
var fk61 = entityType6.AddForeignKey(entityType5.GetKey(), new[] { entityType6.GetProperty("Kool5Id") });
entityType1.AddNavigation(new Navigation(fk11, "NavTo2", pointsToPrincipal: true));
entityType1.AddNavigation(new Navigation(fk21, "NavTo2s", pointsToPrincipal: false));
entityType2.AddNavigation(new Navigation(fk21, "NavTo1", pointsToPrincipal: true));
entityType2.AddNavigation(new Navigation(fk11, "NavTo1s", pointsToPrincipal: false));
entityType2.AddNavigation(new Navigation(fk22, "NavTo3", pointsToPrincipal: true));
entityType3.AddNavigation(new Navigation(fk22, "NavTo2s", pointsToPrincipal: false));
entityType3.AddNavigation(new Navigation(fk31, "NavTo4", pointsToPrincipal: true));
entityType4.AddNavigation(new Navigation(fk31, "NavTo3s", pointsToPrincipal: false));
entityType5.AddNavigation(new Navigation(fk61, "Kool6s", pointsToPrincipal: false));
entityType6.AddNavigation(new Navigation(fk61, "Kool5", pointsToPrincipal: true));
return model;
}
示例2: BuildModel
private static Model BuildModel()
{
var model = new Model();
var entityType = new EntityType(typeof(Banana));
var pkProperty = entityType.AddProperty("Id", typeof(int));
var fkProperty = entityType.AddProperty("Fk", typeof(int));
entityType.SetKey(pkProperty);
var fk = entityType.AddForeignKey(entityType.GetKey(), fkProperty);
entityType.AddProperty("Name", typeof(string));
model.AddEntityType(entityType);
entityType.AddNavigation(new Navigation(fk, "LesserBananas", pointsToPrincipal: false));
entityType.AddNavigation(new Navigation(fk, "TopBanana", pointsToPrincipal: true));
return model;
}
示例3: Reference_navigation_properties_must_be_of_the_target_type
public void Reference_navigation_properties_must_be_of_the_target_type()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
Assert.Equal(
Strings.NavigationSingleWrongClrType("OrderCustomer", typeof(Order).FullName, typeof(Order).FullName, typeof(Customer).FullName),
Assert.Throws<InvalidOperationException>(
() => orderType.AddNavigation("OrderCustomer", customerForeignKey, pointsToPrincipal: true)).Message);
Assert.Equal(
Strings.NavigationSingleWrongClrType("DerivedCustomer", typeof(Order).FullName, typeof(SpecialCustomer).FullName, typeof(Customer).FullName),
Assert.Throws<InvalidOperationException>(
() => orderType.AddNavigation("DerivedCustomer", customerForeignKey, pointsToPrincipal: true)).Message);
}
示例4: Multiple_sets_of_navigations_using_the_same_foreign_key_are_not_allowed
public void Multiple_sets_of_navigations_using_the_same_foreign_key_are_not_allowed()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
customerType.AddNavigation("EnumerableOrders", customerForeignKey, pointsToPrincipal: false);
Assert.Equal(
Strings.MultipleNavigations("Orders", "EnumerableOrders", typeof(Customer).FullName),
Assert.Throws<InvalidOperationException>(
() => customerType.AddNavigation("Orders", customerForeignKey, pointsToPrincipal: false)).Message);
}
示例5: Adding_a_navigation_that_doesnt_match_a_CLR_property_throws
public void Adding_a_navigation_that_doesnt_match_a_CLR_property_throws()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
Assert.Equal(
Strings.NoClrNavigation("Snook", typeof(Order).FullName),
Assert.Throws<InvalidOperationException>(
() => orderType.AddNavigation("Snook", customerForeignKey, pointsToPrincipal: true)).Message);
}
示例6: Collection_navigation_properties_must_be_IEnumerables_of_the_target_type
public void Collection_navigation_properties_must_be_IEnumerables_of_the_target_type()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
Assert.Equal(
Strings.NavigationCollectionWrongClrType("NotCollectionOrders", typeof(Customer).FullName, typeof(Order).FullName, typeof(Order).FullName),
Assert.Throws<InvalidOperationException>(
() => customerType.AddNavigation("NotCollectionOrders", customerForeignKey, pointsToPrincipal: false)).Message);
Assert.Equal(
Strings.NavigationCollectionWrongClrType("DerivedOrders", typeof(Customer).FullName, typeof(IEnumerable<SpecialOrder>).FullName, typeof(Order).FullName),
Assert.Throws<InvalidOperationException>(
() => customerType.AddNavigation("DerivedOrders", customerForeignKey, pointsToPrincipal: false)).Message);
}
示例7: Adding_a_navigation_that_belongs_to_a_different_type_throws
public void Adding_a_navigation_that_belongs_to_a_different_type_throws()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
Assert.Equal(
Strings.NavigationAlreadyOwned("Customer", typeof(Customer).FullName, typeof(Order).FullName),
Assert.Throws<InvalidOperationException>(() => customerType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true)).Message);
}
示例8: Adding_a_navigation_pointing_to_a_shadow_entity_type_throws
public void Adding_a_navigation_pointing_to_a_shadow_entity_type_throws()
{
var customerType = new EntityType("Customer", new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty("Id", typeof(int), shadowProperty: true));
var orderType = new EntityType(typeof(Order), new Model());
var foreignKeyProperty = orderType.GetOrAddProperty("CustomerId", typeof(int), shadowProperty: true);
var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
Assert.Equal(
Strings.NavigationToShadowEntity("Customer", typeof(Order).FullName, "Customer"),
Assert.Throws<InvalidOperationException>(
() => orderType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true)).Message);
}
示例9: Adding_a_new_navigation_with_a_name_that_already_exists_throws
public void Adding_a_new_navigation_with_a_name_that_already_exists_throws()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
orderType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true);
Assert.Equal(
Strings.DuplicateNavigation("Customer", typeof(Order).FullName),
Assert.Throws<InvalidOperationException>(
() => orderType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true)).Message);
}
示例10: Can_add_and_remove_navigations
public void Can_add_and_remove_navigations()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var foreignKeyProperty = orderType.GetOrAddProperty(Order.CustomerIdProperty);
var customerForeignKey = orderType.GetOrAddForeignKey(foreignKeyProperty, customerKey);
Assert.Null(orderType.RemoveNavigation(new Navigation("Customer", customerForeignKey, pointsToPrincipal: true)));
var customerNavigation = orderType.AddNavigation("Customer", customerForeignKey, pointsToPrincipal: true);
var ordersNavigation = customerType.AddNavigation("Orders", customerForeignKey, pointsToPrincipal: false);
Assert.Equal("Customer", customerNavigation.Name);
Assert.Same(orderType, customerNavigation.EntityType);
Assert.Same(customerForeignKey, customerNavigation.ForeignKey);
Assert.True(customerNavigation.PointsToPrincipal);
Assert.False(customerNavigation.IsCollection());
Assert.Same(customerType, customerNavigation.GetTargetType());
Assert.Same(customerNavigation, customerForeignKey.GetNavigationToPrincipal());
Assert.Equal("Orders", ordersNavigation.Name);
Assert.Same(customerType, ordersNavigation.EntityType);
Assert.Same(customerForeignKey, ordersNavigation.ForeignKey);
Assert.False(ordersNavigation.PointsToPrincipal);
Assert.True(ordersNavigation.IsCollection());
Assert.Same(orderType, ordersNavigation.GetTargetType());
Assert.Same(ordersNavigation, customerForeignKey.GetNavigationToDependent());
Assert.Same(customerNavigation, orderType.Navigations.Single());
Assert.Same(ordersNavigation, customerType.Navigations.Single());
Assert.Same(customerNavigation, orderType.RemoveNavigation(customerNavigation));
Assert.Null(orderType.RemoveNavigation(customerNavigation));
Assert.Empty(orderType.Navigations);
Assert.Same(ordersNavigation, customerType.RemoveNavigation(new Navigation("Orders", customerForeignKey, pointsToPrincipal: false)));
Assert.Empty(customerType.Navigations);
}
示例11: Navigations_are_ordered_by_name
public void Navigations_are_ordered_by_name()
{
var customerType = new EntityType(typeof(Customer), new Model());
var customerKey = customerType.GetOrAddKey(customerType.GetOrAddProperty(Customer.IdProperty));
var orderType = new EntityType(typeof(Order), new Model());
var customerForeignKeyProperty = orderType.AddProperty(Order.CustomerIdProperty);
var customerForeignKey = orderType.AddForeignKey(customerForeignKeyProperty, customerKey);
var specialOrderType = new EntityType(typeof(SpecialOrder), new Model());
var specialCustomerForeignKeyProperty = specialOrderType.AddProperty(Order.CustomerIdProperty);
var specialCustomerForeignKey = specialOrderType.AddForeignKey(specialCustomerForeignKeyProperty, customerKey);
var navigation2 = customerType.AddNavigation("Orders", customerForeignKey, pointsToPrincipal: false);
var navigation1 = customerType.AddNavigation("DerivedOrders", specialCustomerForeignKey, pointsToPrincipal: false);
Assert.True(new[] { navigation1, navigation2 }.SequenceEqual(customerType.Navigations));
}
示例12: Navigation_back_pointer_is_fixed_up_as_navigation_is_added_and_removed
public void Navigation_back_pointer_is_fixed_up_as_navigation_is_added_and_removed()
{
var entityType1 = new EntityType(typeof(Customer));
entityType1.SetKey(entityType1.AddProperty(Customer.IdProperty));
var entityType2 = new EntityType(typeof(Customer));
var navigation
= new Navigation(
new ForeignKey(
entityType1.GetKey(),
new[] { entityType1.AddProperty(Customer.IdProperty) }), "Nav", pointsToPrincipal: true);
entityType1.AddNavigation(navigation);
Assert.Same(entityType1, navigation.EntityType);
entityType2.AddNavigation(navigation);
Assert.Same(entityType2, navigation.EntityType);
Assert.Empty(entityType1.Navigations);
entityType2.RemoveNavigation(navigation);
Assert.Empty(entityType2.Navigations);
Assert.Null(navigation.EntityType);
}
示例13: Can_add_navigations
public void Can_add_navigations()
{
var entityType = new EntityType(typeof(Order));
var navigation = new Navigation(new Mock<ForeignKey>().Object, "Milk", pointsToPrincipal: true);
entityType.AddNavigation(navigation);
Assert.Same(navigation, entityType.Navigations.Single());
Assert.Same(entityType, navigation.EntityType);
}