本文整理汇总了C#中Microsoft.Data.Entity.Metadata.Model.AddForeignKey方法的典型用法代码示例。如果您正苦于以下问题:C# Model.AddForeignKey方法的具体用法?C# Model.AddForeignKey怎么用?C# Model.AddForeignKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Data.Entity.Metadata.Model
的用法示例。
在下文中一共展示了Model.AddForeignKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Setting_ClrType_throws_when_referenced
public void Setting_ClrType_throws_when_referenced()
{
var entityType = new Model().AddEntityType(typeof(object));
var principalProperty = entityType.AddProperty("Kake");
var key = entityType.AddKey(principalProperty);
var dependentProperty = entityType.AddProperty("Alaska");
entityType.AddForeignKey(dependentProperty, key, entityType);
Assert.Equal(CoreStrings.PropertyClrTypeCannotBeChangedWhenReferenced("Kake", "{'Alaska'}", "object"),
Assert.Throws<InvalidOperationException>(() =>
principalProperty.ClrType = typeof(int)).Message);
Assert.Equal(typeof(string), ((IProperty)principalProperty).ClrType);
}
示例2: CreateSelfRefFK
private ForeignKey CreateSelfRefFK()
{
var entityType = new Model().AddEntityType(typeof(SelfRef));
var pk = entityType.GetOrSetPrimaryKey(entityType.GetOrAddProperty("Id", typeof(int)));
var fkProp = entityType.GetOrAddProperty("SelfRefId", typeof(int?));
var fk = entityType.AddForeignKey(new[] { fkProp }, pk);
fk.IsUnique = true;
entityType.AddNavigation("SelfRefPrincipal", fk, pointsToPrincipal: true);
entityType.AddNavigation("SelfRefDependent", fk, pointsToPrincipal: false);
return fk;
}
示例3: CreateOneToManyFK
private ForeignKey CreateOneToManyFK()
{
var principalEntityType = new Model().AddEntityType(typeof(OneToManyPrincipal));
var pk = principalEntityType.GetOrSetPrimaryKey(principalEntityType.GetOrAddProperty("Id", typeof(int)));
var dependentEntityType = new Model().AddEntityType(typeof(OneToManyDependent));
var fkProp = dependentEntityType.GetOrAddProperty("Id", typeof(int));
return dependentEntityType.AddForeignKey(new[] { fkProp }, pk);
}