本文整理汇总了C#中EntityType.GetDerivedTypes方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.GetDerivedTypes方法的具体用法?C# EntityType.GetDerivedTypes怎么用?C# EntityType.GetDerivedTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.GetDerivedTypes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Apply
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual bool Apply(InternalEntityTypeBuilder entityTypeBuilder, EntityType oldBaseType)
{
if (oldBaseType != null
&& oldBaseType.BaseType == null
&& !oldBaseType.GetDerivedTypes().Any())
{
var oldBaseTypeBuilder = oldBaseType.Builder;
oldBaseTypeBuilder?.Relational(ConfigurationSource.Convention).HasDiscriminator(propertyInfo: null);
}
var entityType = entityTypeBuilder.Metadata;
var derivedEntityTypes = entityType.GetDerivedTypes().ToList();
DiscriminatorBuilder discriminator;
if (entityType.BaseType == null)
{
if (!derivedEntityTypes.Any())
{
entityTypeBuilder.Relational(ConfigurationSource.Convention).HasDiscriminator(propertyInfo: null);
return true;
}
discriminator = entityTypeBuilder.Relational(ConfigurationSource.Convention)
.HasDiscriminator(typeof(string));
}
else
{
if (entityTypeBuilder.Relational(ConfigurationSource.Convention).HasDiscriminator(propertyInfo: null) == null)
{
// TODO: log warning that the current discriminator couldn't be removed
return true;
}
var rootTypeBuilder = entityType.RootType().Builder;
discriminator = rootTypeBuilder?.Relational(ConfigurationSource.Convention).HasDiscriminator(typeof(string));
if (entityType.BaseType.BaseType == null)
{
discriminator?.HasValue(entityType.BaseType.Name, entityType.BaseType.DisplayName());
}
}
if (discriminator != null)
{
discriminator.HasValue(entityTypeBuilder.Metadata.Name, entityTypeBuilder.Metadata.DisplayName());
SetDefaultDiscriminatorValues(derivedEntityTypes, discriminator);
}
return true;
}