本文整理汇总了C#中EntityType.SetKey方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.SetKey方法的具体用法?C# EntityType.SetKey怎么用?C# EntityType.SetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.SetKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsRequired_when_dependent_property_nullable
public void IsRequired_when_dependent_property_nullable()
{
var entityType = new EntityType("E");
entityType.SetKey(entityType.AddProperty("Id", typeof(int)));
var dependentProp = entityType.AddProperty("P", typeof(int?));
var foreignKey = new ForeignKey(entityType.GetKey(), new[] { dependentProp });
Assert.False(foreignKey.IsRequired);
}
示例2: Select_returns_null_when_ValueGenerationOnAdd_is_not_Client
public void Select_returns_null_when_ValueGenerationOnAdd_is_not_Client()
{
var entityType = new EntityType("Entity");
var property = entityType.AddProperty("Id", typeof(long));
entityType.SetKey(property);
var result = CreateSelector().Select(property);
Assert.Null(result);
}
示例3: Select_throws_when_non_integer_column_key
public void Select_throws_when_non_integer_column_key()
{
var selector = CreateSelector();
var entityType = new EntityType("Entity");
var property = entityType.AddProperty("Id", typeof(int));
property.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
entityType.SetKey(property);
Assert.Throws<NotSupportedException>(() => selector.Select(property));
}
示例4: Select_throws_when_composite_key
public void Select_throws_when_composite_key()
{
var selector = CreateSelector();
var entityType = new EntityType("Entity");
var property = entityType.AddProperty("Id1", typeof(long));
property.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
entityType.SetKey(property, entityType.AddProperty("Id2", typeof(long)));
Assert.Throws<NotSupportedException>(() => selector.Select(property));
}
示例5: Select_returns_tempFactory_when_single_long_key
public void Select_returns_tempFactory_when_single_long_key()
{
var entityType = new EntityType("Entity");
var property = entityType.AddProperty("Id", typeof(long));
property.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
entityType.SetKey(property);
var result = CreateSelector().Select(property);
Assert.IsType<SimpleValueGeneratorFactory<TemporaryValueGenerator>>(result);
}
示例6: Select_returns_tempFactory_when_single_integer_column_key
public void Select_returns_tempFactory_when_single_integer_column_key()
{
var entityType = new EntityType("Entity");
var property = entityType.AddProperty("Id", typeof(int));
property.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
property[MetadataExtensions.Annotations.StorageTypeName] = "INTEGER";
entityType.SetKey(property);
var result = CreateSelector().Select(property);
Assert.IsType<SimpleValueGeneratorFactory<TemporaryValueGenerator>>(result);
}
示例7: Apply
public virtual void Apply(EntityType entityType)
{
if (entityType.TryGetKey() == null)
{
var pk = entityType.TryGetProperty("PartitionKey");
var rk = entityType.TryGetProperty("RowKey");
if (pk != null
&& rk != null)
{
entityType.SetKey(pk, rk);
}
}
}
示例8: Can_create_foreign_key
public void Can_create_foreign_key()
{
var entityType = new EntityType("E");
var dependentProp = entityType.AddProperty("P", typeof(int));
var principalProp = entityType.AddProperty("Id", typeof(int));
entityType.SetKey(principalProp);
var foreignKey
= new ForeignKey(entityType.GetKey(), new[] { dependentProp })
{
IsUnique = true,
};
Assert.Same(entityType, foreignKey.ReferencedEntityType);
Assert.Same(principalProp, foreignKey.ReferencedProperties.Single());
Assert.Same(dependentProp, foreignKey.Properties.Single());
Assert.True(foreignKey.IsUnique);
}
示例9: BuildModel
protected override Model BuildModel()
{
var model = new Model();
var entityType1 = new EntityType("SomeEntity");
model.AddEntityType(entityType1);
var key1 = entityType1.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false);
key1.ValueGenerationOnSave = ValueGenerationOnSave.WhenInserting;
key1.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
entityType1.SetKey(key1);
entityType1.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);
var entityType2 = new EntityType("SomeDependentEntity");
model.AddEntityType(entityType2);
var key2a = entityType2.AddProperty("Id1", typeof(int), shadowProperty: true, concurrencyToken: false);
var key2b = entityType2.AddProperty("Id2", typeof(string), shadowProperty: true, concurrencyToken: false);
entityType2.SetKey(key2a, key2b);
var fk = entityType2.AddProperty("SomeEntityId", typeof(int), shadowProperty: true, concurrencyToken: false);
entityType2.AddForeignKey(entityType1.GetKey(), new[] { fk });
var justAProperty = entityType2.AddProperty("JustAProperty", typeof(int), shadowProperty: true, concurrencyToken: false);
justAProperty.ValueGenerationOnSave = ValueGenerationOnSave.WhenInserting;
justAProperty.ValueGenerationOnAdd = ValueGenerationOnAdd.Client;
var entityType3 = new EntityType(typeof(FullNotificationEntity));
model.AddEntityType(entityType3);
entityType3.SetKey(entityType3.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));
entityType3.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);
var entityType4 = new EntityType(typeof(ChangedOnlyEntity));
model.AddEntityType(entityType4);
entityType4.SetKey(entityType4.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));
entityType4.AddProperty("Name", typeof(string), shadowProperty: true, concurrencyToken: true);
var entityType5 = new EntityType("SomeMoreDependentEntity");
model.AddEntityType(entityType5);
var key5 = entityType5.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false);
entityType5.SetKey(key5);
var fk5a = entityType5.AddProperty("Fk1", typeof(int), shadowProperty: true, concurrencyToken: false);
var fk5b = entityType5.AddProperty("Fk2", typeof(string), shadowProperty: true, concurrencyToken: false);
entityType5.AddForeignKey(entityType2.GetKey(), new[] { fk5a, fk5b });
return model;
}
示例10: 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);
}
示例11: BuildModel
private static IModel BuildModel(ValueGenerationOnSave keyStrategy, ValueGenerationOnSave nonKeyStrategy)
{
var model = new Metadata.Model();
var entityType = new EntityType(typeof(T1));
var key = entityType.AddProperty("Id", typeof(int));
key.ValueGenerationOnSave = keyStrategy;
key.SetColumnName("Col1");
entityType.SetKey(key);
var nonKey = entityType.AddProperty("Name", typeof(string));
nonKey.SetColumnName("Col2");
nonKey.ValueGenerationOnSave = nonKeyStrategy;
model.AddEntityType(entityType);
return model;
}
示例12: CreateModel
private static IModel CreateModel()
{
var model = new Model();
var entityType = new EntityType("Entity");
var property = entityType.AddProperty("Id", typeof(int));
entityType.SetTableName("MyTable");
entityType.SetSchema("dbo");
entityType.SetKey(property);
entityType.GetKey().SetKeyName("MyPK");
model.AddEntityType(entityType);
return model;
}
示例13: FK_properties_are_marked_as_requiring_original_values
public void FK_properties_are_marked_as_requiring_original_values()
{
var entityType = new EntityType(typeof(FullNotificationEntity));
entityType.SetKey(entityType.AddProperty("Id", typeof(int)));
Assert.Equal(-1, entityType.GetProperty("Id").OriginalValueIndex);
entityType.AddForeignKey(entityType.GetKey(), new[] { entityType.AddProperty("Id", typeof(int)) });
Assert.Equal(0, entityType.GetProperty("Id").OriginalValueIndex);
}
示例14: Generate_migration_metadata_class
public void Generate_migration_metadata_class()
{
var model = new Model();
var entityType = new EntityType("Entity");
entityType.SetKey(entityType.AddProperty("Id", typeof(int)));
model.AddEntityType(entityType);
var migration
= new MigrationMetadata("000000000000001_Name")
{
TargetModel = model
};
var codeGenerator = new CSharpMigrationCodeGenerator(new CSharpModelCodeGenerator());
var stringBuilder = new IndentedStringBuilder();
codeGenerator.GenerateMigrationMetadataClass("MyNamespace", "MyClass", migration, stringBuilder);
Assert.Equal(
@"using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations.Infrastructure;
using System;
namespace MyNamespace
{
public partial class MyClass : IMigrationMetadata
{
string IMigrationMetadata.MigrationId
{
get
{
return ""000000000000001_Name"";
}
}
IModel IMigrationMetadata.TargetModel
{
get
{
var builder = new ModelBuilder();
builder.Entity(""Entity"", b =>
{
b.Property<int>(""Id"");
b.Key(""Id"");
});
return builder.Model;
}
}
}
}",
stringBuilder.ToString());
}
示例15: CreateModelWithForeignKeys
private static IModel CreateModelWithForeignKeys()
{
var model = new Model();
var houseType = new EntityType("Ho!use[]");
var houseId = houseType.AddProperty("Id", typeof(int));
houseType.SetKey(houseId);
model.AddEntityType(houseType);
var customerType = new EntityType(@"Customer");
var customerId = customerType.AddProperty("Id", typeof(int));
var customerFkProperty = customerType.AddProperty("HouseId", typeof(int));
customerFkProperty.SetColumnName(@"House[""Id]Column");
customerType.SetSchema("dbo");
customerType.SetTableName(@"Cus[""om.er]s");
customerType.SetKey(customerId);
customerType.GetKey().SetKeyName(@"My[""PK]");
customerType.GetKey().Annotations.Add(new Annotation(@"My""PK""Annotat!on", @"""Foo"""));
var customerFk = customerType.AddForeignKey(houseType.GetKey(), customerFkProperty);
customerFk.SetKeyName(@"My_[""FK]");
customerFk.Annotations.Add(new Annotation(@"My""FK""Annotation", @"""Bar"""));
model.AddEntityType(customerType);
var orderType = new EntityType(@"Order");
var orderId = orderType.AddProperty(@"OrderId", typeof(int));
var orderFK = orderType.AddProperty(@"CustomerId", typeof(int));
orderType.SetSchema("dbo");
orderType.SetKey(orderId);
orderType.SetTableName(@"Ord[""e.r]s");
orderType.AddForeignKey(customerType.GetKey(), orderFK);
orderType.Annotations.Add(new Annotation("Random annotation", "42"));
model.AddEntityType(orderType);
return model;
}