擴展entity framework core 實現預設字元串長度,decimal精度,entity自動註冊和配置

来源:http://www.cnblogs.com/calvinK/archive/2017/07/25/7234872.html
-Advertisement-
Play Games

文章以efcore 2.0.0 preview2.測試驗證通過。其他版本不保證使用,但是思路不會差太遠。 "源代碼" ,報道越短,事情越嚴重!文章越短,內容越精悍! 目標: 1.實現entity的自動發現和mapper設置. 2.預設字元串長度,而不是nvarchar(max). 3.decimal ...


文章以efcore 2.0.0-preview2.測試驗證通過。其他版本不保證使用,但是思路不會差太遠。源代碼,報道越短,事情越嚴重!文章越短,內容越精悍!

目標:
1.實現entity的自動發現和mapper設置.
2.預設字元串長度,而不是nvarchar(max).
3.decimal設置精度

實現目標1:繼承RelationalModelCustomizer,重寫Customize方法。

當然,我們也可以重寫dbcontext的OnModelCreating方法,but,我們怎麼能這麼low呢。必須要用點高級玩意是吧,當然這也是更底層的擴展方式。項目裡面有多個dbcontext的話,在這裡集中擴展管理比較方便。
在然後,這個RelationalModelCustomizer繼承自ModelCustomizer。在聯想到efcore未來的版本會支持redis,nosql什麼的。到時候估計還回有一個osqlModelCustomizer之類的吧,期待中......

實現目標2、3:繼承自CoreConventionSetBuilder類,重寫CreateConventionSet方法。

重寫CreateConventionSet方法,能拿到關鍵的ConventionSet對象。這個對象囊括了諸多的約定配置等等。比如maxlengthattribute屬性標記,stringlength屬性標記,timestamp屬性標記,表id的自動發現規則等等等。。。
那,我們增加2個小小的約定:字元串預設長度(StringDefaultLengthConvention),和decimal精度設置attribute(DecimalPrecisionAttributeConvention)及fluntapi方式.

文章的最後附efcore 所有的可替換擴展service。

//servie,DI註入替換.
services.AddSingleton<IModelCustomizer, MyRelationalModelCustomizer>();
services.AddSingleton<ICoreConventionSetBuilder, MyCoreConventionSetBuilder>();

//實現entity的自動發現和mapper設置
public class MyRelationalModelCustomizer : RelationalModelCustomizer
{
    public MyRelationalModelCustomizer(ModelCustomizerDependencies dependencies)
        : base(dependencies){}

    public override void Customize(ModelBuilder modelBuilder, DbContext dbContext)
    {
        base.Customize(modelBuilder, dbContext);
        var sp = (IInfrastructure<IServiceProvider>)dbContext;
        var dbOptions = sp.Instance.GetServices<DbContextOptions>();
        foreach (var item in dbOptions)
        {
            if (item.ContextType == dbContext.GetType())
                ConfigureDbContextEntityService.Configure(modelBuilder, item, dbContext);
        }
    }
}

public class MyCoreConventionSetBuilder : CoreConventionSetBuilder
{
    public MyCoreConventionSetBuilder(CoreConventionSetBuilderDependencies dependencies) : base(dependencies){}
    public override ConventionSet CreateConventionSet()
    {
        var conventionSet = base.CreateConventionSet();
        //預設字元串長度,而不是nvarchar(max).
        //為什麼要insert(0,obj),則是因為這個預設規則要最優先處理,如果後續有規則的話就直接覆蓋了。
        //propertyBuilder.HasMaxLength(32, ConfigurationSource.Convention);
        //理論上我指定了規則的級別為.Convention,應該和順序就沒有關係了。but,還沒有完成測試,所以我也不知道
        conventionSet.PropertyAddedConventions.Insert(0, new StringDefaultLengthConvention());
        //decimal設置精度
        conventionSet.PropertyAddedConventions.Add(new DecimalPrecisionAttributeConvention());
        return conventionSet;
    }
}

下麵是StringDefaultLengthConvention和DecimalPrecisionAttributeConvention的實現代碼

//字元串預設長度
public class StringDefaultLengthConvention : IPropertyAddedConvention
{
    public InternalPropertyBuilder Apply(InternalPropertyBuilder propertyBuilder)
    {
        if (propertyBuilder.Metadata.ClrType == typeof(string))
            propertyBuilder.HasMaxLength(32, ConfigurationSource.Convention);
        return propertyBuilder;
    }
}
//attribute方式設置decimal精度
public class DecimalPrecisionAttributeConvention : PropertyAttributeConvention<DecimalPrecisionAttribute>
{
    public override InternalPropertyBuilder Apply(InternalPropertyBuilder propertyBuilder, DecimalPrecisionAttribute attribute, MemberInfo clrMember)
    {
        if (propertyBuilder.Metadata.ClrType == typeof(decimal))
            propertyBuilder.HasPrecision(attribute.Precision, attribute.Scale);
        return propertyBuilder;
    }

/// <summary>
/// decimal類型設置精度
/// </summary>
/// <param name="propertyBuilder"></param>
/// <param name="precision">精度</param>
/// <param name="scale">小數位數</param>
public static PropertyBuilder<TProperty> HasPrecision<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, int precision = 18, int scale = 4)
{
    //fluntapi方式設置精度  
    ((IInfrastructure<InternalPropertyBuilder>)propertyBuilder).Instance.HasPrecision(precision, scale);

    return propertyBuilder;
}

public static InternalPropertyBuilder HasPrecision(this InternalPropertyBuilder propertyBuilder, int precision, int scale)
{
    propertyBuilder.Relational(ConfigurationSource.Explicit).HasColumnType($"decimal({precision},{scale})");

    return propertyBuilder;
}

以上就是實現的代碼,就這麼幾行。嗯,還是挺簡單的.

--------------

以下,則是efcore的源代碼。展示瞭如此之多的可擴展。隨著DI的運用和微軟的開放,嗯。用爛啦,用炸拉(^_^)

//各種規則和約定
public virtual ConventionSet AddConventions(ConventionSet conventionSet)
{
    ValueGeneratorConvention valueGeneratorConvention = new RelationalValueGeneratorConvention();

    ReplaceConvention(conventionSet.BaseEntityTypeChangedConventions, valueGeneratorConvention);
    ReplaceConvention(conventionSet.PrimaryKeyChangedConventions, valueGeneratorConvention);
    ReplaceConvention(conventionSet.ForeignKeyAddedConventions, valueGeneratorConvention);
    ReplaceConvention(conventionSet.ForeignKeyRemovedConventions, valueGeneratorConvention);

    var relationalColumnAttributeConvention = new RelationalColumnAttributeConvention();

    conventionSet.PropertyAddedConventions.Add(relationalColumnAttributeConvention);

    var sharedTableConvention = new SharedTableConvention();

    conventionSet.EntityTypeAddedConventions.Add(new RelationalTableAttributeConvention());
    conventionSet.EntityTypeAddedConventions.Add(sharedTableConvention);
    conventionSet.BaseEntityTypeChangedConventions.Add(new DiscriminatorConvention());
    conventionSet.BaseEntityTypeChangedConventions.Add(
        new TableNameFromDbSetConvention(Dependencies.Context?.Context, Dependencies.SetFinder));
    conventionSet.EntityTypeAnnotationChangedConventions.Add(sharedTableConvention);
    conventionSet.PropertyFieldChangedConventions.Add(relationalColumnAttributeConvention);
    conventionSet.PropertyAnnotationChangedConventions.Add((RelationalValueGeneratorConvention)valueGeneratorConvention);
    conventionSet.ForeignKeyUniquenessChangedConventions.Add(sharedTableConvention);
    conventionSet.ForeignKeyOwnershipChangedConventions.Add(sharedTableConvention);

    conventionSet.ModelBuiltConventions.Add(new RelationalTypeMappingConvention(Dependencies.TypeMapper));
    conventionSet.ModelBuiltConventions.Add(sharedTableConvention);

    conventionSet.ModelAnnotationChangedConventions.Add(new RelationalDbFunctionConvention());

    return conventionSet;
}
//還是各種規則和約定
public virtual ConventionSet CreateConventionSet()
{
    var conventionSet = new ConventionSet();

    var propertyDiscoveryConvention = new PropertyDiscoveryConvention(Dependencies.TypeMapper);
    var keyDiscoveryConvention = new KeyDiscoveryConvention();
    var inversePropertyAttributeConvention = new InversePropertyAttributeConvention(Dependencies.TypeMapper);
    var relationshipDiscoveryConvention = new RelationshipDiscoveryConvention(Dependencies.TypeMapper);

    conventionSet.EntityTypeAddedConventions.Add(new NotMappedEntityTypeAttributeConvention());
    conventionSet.EntityTypeAddedConventions.Add(new NotMappedMemberAttributeConvention());
    conventionSet.EntityTypeAddedConventions.Add(new BaseTypeDiscoveryConvention());
    conventionSet.EntityTypeAddedConventions.Add(propertyDiscoveryConvention);
    conventionSet.EntityTypeAddedConventions.Add(keyDiscoveryConvention);
    conventionSet.EntityTypeAddedConventions.Add(inversePropertyAttributeConvention);
    conventionSet.EntityTypeAddedConventions.Add(relationshipDiscoveryConvention);
    conventionSet.EntityTypeAddedConventions.Add(new DerivedTypeDiscoveryConvention());
    conventionSet.EntityTypeIgnoredConventions.Add(inversePropertyAttributeConvention);

    var foreignKeyIndexConvention = new ForeignKeyIndexConvention();
    var valueGeneratorConvention = new ValueGeneratorConvention();

    conventionSet.BaseEntityTypeChangedConventions.Add(propertyDiscoveryConvention);
    conventionSet.BaseEntityTypeChangedConventions.Add(keyDiscoveryConvention);
    conventionSet.BaseEntityTypeChangedConventions.Add(inversePropertyAttributeConvention);
    conventionSet.BaseEntityTypeChangedConventions.Add(relationshipDiscoveryConvention);
    conventionSet.BaseEntityTypeChangedConventions.Add(foreignKeyIndexConvention);
    conventionSet.BaseEntityTypeChangedConventions.Add(valueGeneratorConvention );

    // An ambiguity might have been resolved
    conventionSet.EntityTypeMemberIgnoredConventions.Add(inversePropertyAttributeConvention);
    conventionSet.EntityTypeMemberIgnoredConventions.Add(relationshipDiscoveryConvention);

    var keyAttributeConvention = new KeyAttributeConvention();
    var foreignKeyPropertyDiscoveryConvention = new ForeignKeyPropertyDiscoveryConvention();
    var backingFieldConvention = new BackingFieldConvention();
    var concurrencyCheckAttributeConvention = new ConcurrencyCheckAttributeConvention();
    var databaseGeneratedAttributeConvention = new DatabaseGeneratedAttributeConvention();
    var requiredPropertyAttributeConvention = new RequiredPropertyAttributeConvention();
    var maxLengthAttributeConvention = new MaxLengthAttributeConvention();
    var stringLengthAttributeConvention = new StringLengthAttributeConvention();
    var timestampAttributeConvention = new TimestampAttributeConvention();

    conventionSet.PropertyAddedConventions.Add(backingFieldConvention);
    conventionSet.PropertyAddedConventions.Add(concurrencyCheckAttributeConvention);
    conventionSet.PropertyAddedConventions.Add(databaseGeneratedAttributeConvention);
    conventionSet.PropertyAddedConventions.Add(requiredPropertyAttributeConvention);
    conventionSet.PropertyAddedConventions.Add(maxLengthAttributeConvention);
    conventionSet.PropertyAddedConventions.Add(stringLengthAttributeConvention);
    conventionSet.PropertyAddedConventions.Add(timestampAttributeConvention);
    conventionSet.PropertyAddedConventions.Add(keyDiscoveryConvention);
    conventionSet.PropertyAddedConventions.Add(foreignKeyPropertyDiscoveryConvention);
    conventionSet.PropertyAddedConventions.Add(keyAttributeConvention);

    conventionSet.PrimaryKeyChangedConventions.Add(valueGeneratorConvention);

    conventionSet.KeyAddedConventions.Add(foreignKeyPropertyDiscoveryConvention);
    conventionSet.KeyAddedConventions.Add(foreignKeyIndexConvention);

    conventionSet.KeyRemovedConventions.Add(foreignKeyPropertyDiscoveryConvention);
    conventionSet.KeyRemovedConventions.Add(foreignKeyIndexConvention);
    conventionSet.KeyRemovedConventions.Add(keyDiscoveryConvention);

    var cascadeDeleteConvention = new CascadeDeleteConvention();

    conventionSet.ForeignKeyAddedConventions.Add(new ForeignKeyAttributeConvention(Dependencies.TypeMapper));
    conventionSet.ForeignKeyAddedConventions.Add(foreignKeyPropertyDiscoveryConvention);
    conventionSet.ForeignKeyAddedConventions.Add(keyDiscoveryConvention);
    conventionSet.ForeignKeyAddedConventions.Add(valueGeneratorConvention );
    conventionSet.ForeignKeyAddedConventions.Add(cascadeDeleteConvention);
    conventionSet.ForeignKeyAddedConventions.Add(foreignKeyIndexConvention);

    conventionSet.ForeignKeyRemovedConventions.Add(keyDiscoveryConvention);
    conventionSet.ForeignKeyRemovedConventions.Add(valueGeneratorConvention );
    conventionSet.ForeignKeyRemovedConventions.Add(foreignKeyIndexConvention);

    conventionSet.ForeignKeyUniquenessChangedConventions.Add(foreignKeyPropertyDiscoveryConvention);
    conventionSet.ForeignKeyUniquenessChangedConventions.Add(foreignKeyIndexConvention);

    conventionSet.ForeignKeyOwnershipChangedConventions.Add(new NavigationEagerLoadingConvention());

    conventionSet.ModelBuiltConventions.Add(new ModelCleanupConvention());
    conventionSet.ModelBuiltConventions.Add(keyAttributeConvention);
    conventionSet.ModelBuiltConventions.Add(new IgnoredMembersValidationConvention());
    conventionSet.ModelBuiltConventions.Add(new PropertyMappingValidationConvention(Dependencies.TypeMapper));
    conventionSet.ModelBuiltConventions.Add(new RelationshipValidationConvention());
    conventionSet.ModelBuiltConventions.Add(foreignKeyPropertyDiscoveryConvention);

    conventionSet.NavigationAddedConventions.Add(backingFieldConvention);
    conventionSet.NavigationAddedConventions.Add(new RequiredNavigationAttributeConvention());
    conventionSet.NavigationAddedConventions.Add(inversePropertyAttributeConvention);
    conventionSet.NavigationAddedConventions.Add(foreignKeyPropertyDiscoveryConvention);
    conventionSet.NavigationAddedConventions.Add(relationshipDiscoveryConvention);

    conventionSet.NavigationRemovedConventions.Add(relationshipDiscoveryConvention);

    conventionSet.IndexAddedConventions.Add(foreignKeyIndexConvention);

    conventionSet.IndexRemovedConventions.Add(foreignKeyIndexConvention);

    conventionSet.IndexUniquenessChangedConventions.Add(foreignKeyIndexConvention);

    conventionSet.PropertyNullabilityChangedConventions.Add(cascadeDeleteConvention);

    conventionSet.PrincipalEndChangedConventions.Add(foreignKeyPropertyDiscoveryConvention);

    conventionSet.PropertyFieldChangedConventions.Add(keyDiscoveryConvention);
    conventionSet.PropertyFieldChangedConventions.Add(foreignKeyPropertyDiscoveryConvention);
    conventionSet.PropertyFieldChangedConventions.Add(keyAttributeConvention);
    conventionSet.PropertyFieldChangedConventions.Add(concurrencyCheckAttributeConvention);
    conventionSet.PropertyFieldChangedConventions.Add(databaseGeneratedAttributeConvention);
    conventionSet.PropertyFieldChangedConventions.Add(requiredPropertyAttributeConvention);
    conventionSet.PropertyFieldChangedConventions.Add(maxLengthAttributeConvention);
    conventionSet.PropertyFieldChangedConventions.Add(stringLengthAttributeConvention);
    conventionSet.PropertyFieldChangedConventions.Add(timestampAttributeConvention);
    
    return conventionSet;
}

我就是所有的可替換service啦。不要眼花有點多!,找著合適的用起來!

serviceCollection.AsQueryable()
    .Where(p => p.ServiceType.ToString().StartsWith("Microsoft.EntityFrameworkCore"))
    .Each(sd =>
{
    Console.WriteLine($"{sd.Lifetime.ToString().PadRight(15, ' ')}{sd.ServiceType.FullName}");
});

//output 
//Singleton Microsoft.EntityFrameworkCore.Storage.IDatabaseProvider
//Singleton Microsoft.EntityFrameworkCore.ValueGeneration.IValueGeneratorCache
//Singleton      Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMapper
//Singleton      Microsoft.EntityFrameworkCore.Storage.ISqlGenerationHelper
//Singleton      Microsoft.EntityFrameworkCore.Migrations.IMigrationsAnnotationProvider
//Singleton      Microsoft.EntityFrameworkCore.Storage.IRelationalValueBufferFactoryFactory
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.IModelValidator
//Scoped         Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.IConventionSetBuilder
//Singleton      Microsoft.EntityFrameworkCore.Update.IUpdateSqlGenerator
//Scoped         Microsoft.EntityFrameworkCore.Update.IModificationCommandBatchFactory
//Scoped         Microsoft.EntityFrameworkCore.ValueGeneration.IValueGeneratorSelector
//Scoped         Microsoft.EntityFrameworkCore.Storage.IRelationalConnection
//Singleton      Microsoft.EntityFrameworkCore.Migrations.IMigrationsSqlGenerator
//Scoped         Microsoft.EntityFrameworkCore.Storage.IRelationalDatabaseCreator
//Scoped         Microsoft.EntityFrameworkCore.Migrations.IHistoryRepository
//Scoped         Microsoft.EntityFrameworkCore.Query.ICompiledQueryCacheKeyGenerator
//Scoped         Microsoft.EntityFrameworkCore.Storage.IExecutionStrategyFactory
//Scoped         Microsoft.EntityFrameworkCore.Query.IQueryCompilationContextFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.IMemberTranslator
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.ICompositeMethodCallTranslator
//Singleton      Microsoft.EntityFrameworkCore.Query.Sql.IQuerySqlGeneratorFactory
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.ISingletonOptions
//Singleton      Microsoft.EntityFrameworkCore.ValueGeneration.Internal.ISqlServerValueGeneratorCache
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.Internal.ISqlServerOptions
//Scoped         Microsoft.EntityFrameworkCore.Update.Internal.ISqlServerUpdateSqlGenerator
//Scoped         Microsoft.EntityFrameworkCore.ValueGeneration.Internal.ISqlServerSequenceValueGeneratorFactory
//Scoped         Microsoft.EntityFrameworkCore.Storage.Internal.ISqlServerConnection
//Singleton      Microsoft.EntityFrameworkCore.Storage.IParameterNameGeneratorFactory
//Singleton      Microsoft.EntityFrameworkCore.Migrations.IMigrationsIdGenerator
//Singleton      Microsoft.EntityFrameworkCore.Update.Internal.IKeyValueIndexFactorySource
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.IModelSource
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.IModelCustomizer
//Scoped         Microsoft.EntityFrameworkCore.Migrations.IMigrator
//Singleton      Microsoft.EntityFrameworkCore.Migrations.IMigrationCommandExecutor
//Scoped         Microsoft.EntityFrameworkCore.Migrations.IMigrationsAssembly
//Scoped         Microsoft.EntityFrameworkCore.Storage.IDatabase
//Scoped         Microsoft.EntityFrameworkCore.Update.IBatchExecutor
//Singleton      Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory
//Singleton      Microsoft.EntityFrameworkCore.Storage.IRawSqlCommandBuilder
//Scoped         Microsoft.EntityFrameworkCore.Update.ICommandBatchPreparer
//Singleton      Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer
//Singleton      Microsoft.EntityFrameworkCore.Storage.ITypeMapper
//Scoped         Microsoft.EntityFrameworkCore.Storage.IDatabaseCreator
//Scoped         Microsoft.EntityFrameworkCore.Storage.IDbContextTransactionManager
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.IMaterializerFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.Internal.IShaperCommandContextFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.IConditionalRemovingExpressionVisitorFactory
//Scoped         Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.ICompositePredicateExpressionVisitorFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.Expressions.ISelectExpressionFactory
//Scoped         Microsoft.EntityFrameworkCore.Query.Internal.IExpressionPrinter
//Scoped         Microsoft.EntityFrameworkCore.Query.IRelationalResultOperatorHandler
//Scoped         Microsoft.EntityFrameworkCore.Query.IQueryContextFactory
//Scoped         Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.IEntityQueryableExpressionVisitorFactory
//Scoped         Microsoft.EntityFrameworkCore.Query.IEntityQueryModelVisitorFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.IProjectionExpressionVisitorFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.IExpressionFragmentTranslator
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ISqlTranslatingExpressionVisitorFactory
//Scoped         Microsoft.EntityFrameworkCore.Storage.Internal.INamedConnectionStringResolver
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.RelationalCompositeMemberTranslatorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Storage.RelationalSqlGenerationHelperDependencies
//Singleton      Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapperDependencies
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.RelationalCompositeExpressionFragmentTranslatorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidatorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Update.UpdateSqlGeneratorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Query.Sql.QuerySqlGeneratorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionTranslators.RelationalCompositeMethodCallTranslatorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Migrations.MigrationsSqlGeneratorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Migrations.MigrationsAnnotationProviderDependencies
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.SqlTranslatingExpressionVisitorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Storage.ParameterNameGeneratorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Query.Expressions.SelectExpressionDependencies
//Singleton      Microsoft.EntityFrameworkCore.Storage.RelationalValueBufferFactoryDependencies
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalProjectionExpressionVisitorDependencies
//Scoped         Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationalConventionSetBuilderDependencies
//Scoped         Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreatorDependencies
//Scoped         Microsoft.EntityFrameworkCore.Migrations.HistoryRepositoryDependencies
//Scoped         Microsoft.EntityFrameworkCore.Query.RelationalCompiledQueryCacheKeyGeneratorDependencies
//Scoped         Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitorDependencies
//Scoped         Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitorDependencies
//Scoped         Microsoft.EntityFrameworkCore.Storage.RelationalConnectionDependencies
//Scoped         Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseDependencies
//Scoped         Microsoft.EntityFrameworkCore.Query.RelationalQueryCompilationContextDependencies
//Singleton      Microsoft.EntityFrameworkCore.Internal.IDbSetFinder
//Singleton      Microsoft.EntityFrameworkCore.Internal.IDbSetInitializer
//Singleton      Microsoft.EntityFrameworkCore.Internal.IDbSetSource
//Singleton      Microsoft.EntityFrameworkCore.Internal.IEntityFinderSource
//Singleton      Microsoft.EntityFrameworkCore.Metadata.Internal.IEntityMaterializerSource
//Singleton      Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ICoreConventionSetBuilder
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.IModelCacheKeyFactory
//Singleton      Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IInternalEntityEntryFactory
//Singleton      Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IInternalEntityEntrySubscriber
//Singleton      Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IEntityEntryGraphIterator
//Singleton      Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IEntityGraphAttacher
//Singleton      Microsoft.EntityFrameworkCore.Query.Internal.INodeTypeProviderFactory
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IKeyPropagator
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.INavigationFixer
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ILocalViewListener
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IStateManager
//Scoped         Microsoft.EntityFrameworkCore.Internal.IConcurrencyDetector
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IInternalEntityEntryNotifier
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IValueGenerationManager
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IChangeTrackerFactory
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IChangeDetector
//Scoped         Microsoft.EntityFrameworkCore.Internal.IDbContextServices
//Scoped         Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies
//Singleton      Microsoft.EntityFrameworkCore.Query.Internal.ICompiledQueryCache
//Scoped         Microsoft.EntityFrameworkCore.Query.Internal.IAsyncQueryProvider
//Scoped         Microsoft.EntityFrameworkCore.Query.Internal.IQueryCompiler
//Singleton      Microsoft.EntityFrameworkCore.Query.Internal.IQueryAnnotationExtractor
//Scoped         Microsoft.EntityFrameworkCore.Query.Internal.IQueryOptimizer
//Singleton      Microsoft.EntityFrameworkCore.Query.Internal.IEntityTrackingInfoFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.ITaskBlockingExpressionVisitor
//Scoped         Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.IEntityResultFindingExpressionVisitorFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.IMemberAccessBindingExpressionVisitorFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.INavigationRewritingExpressionVisitorFactory
//Singleton      Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.IQuerySourceTracingExpressionVisitorFactory
//Scoped         Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.IRequiresMaterializationExpressionVisitorFactory
//Scoped         Microsoft.EntityFrameworkCore.Query.IResultOperatorHandler
//Singleton      Microsoft.EntityFrameworkCore.Internal.ISingletonOptionsInitialzer
//Singleton      Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger`1
//Singleton Microsoft.EntityFrameworkCore.Diagnostics.ILoggingOptions
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.ISingletonOptions
//Scoped         Microsoft.EntityFrameworkCore.Metadata.IModel
//Scoped         Microsoft.EntityFrameworkCore.Internal.ICurrentDbContext
//Scoped         Microsoft.EntityFrameworkCore.Infrastructure.IDbContextOptions
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IEntityStateListener
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.INavigationListener
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IKeyListener
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IQueryTrackingListener
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IPropertyListener
//Scoped         Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IEntityStateListener
//Scoped         Microsoft.EntityFrameworkCore.Infrastructure.IResettableService
//Scoped         Microsoft.EntityFrameworkCore.Infrastructure.IResettableService
//Singleton      Microsoft.EntityFrameworkCore.Storage.DatabaseProviderDependencies
//Singleton      Microsoft.EntityFrameworkCore.Query.ResultOperatorHandlerDependencies
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.ModelSourceDependencies
//Singleton      Microsoft.EntityFrameworkCore.ValueGeneration.ValueGeneratorCacheDependencies
//Singleton      Microsoft.EntityFrameworkCore.Infrastructure.ModelValidatorDependencies
//Singleton      Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.CoreConventionSetBuilderDependencies
//Scoped         Microsoft.EntityFrameworkCore.Storage.ExecutionStrategyDependencies
//Scoped         Microsoft.EntityFrameworkCore.Query.CompiledQueryCacheKeyGeneratorDependencies
//Scoped         Microsoft.EntityFrameworkCore.Query.QueryContextDependencies
//Scoped         Microsoft.EntityFrameworkCore.ValueGeneration.ValueGeneratorSelectorDependencies
//Scoped         Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitorDependencies
//Scoped         Microsoft.EntityFrameworkCore.Storage.DatabaseDependencies
//Scoped         Microsoft.EntityFrameworkCore.Infrastructure.ModelCustomizerDependencies
//Scoped         Microsoft.EntityFrameworkCore.Infrastructure.ModelCacheKeyFactoryDependencies
//Scoped         Microsoft.EntityFrameworkCore.Query.Internal.QueryCompilationContextDependencies
//Singleton      Microsoft.EntityFrameworkCore.DbContextOptions<Aquirrel.EntityFramework.Test.TestDbContext>
//Singleton Microsoft.EntityFrameworkCore.DbContextOptions
//Singleton Microsoft.EntityFrameworkCore.Infrastructure.IModelCustomizer
//Singleton      Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ICoreConventionSetBuilder

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1:使用win+r打開 運行 控制台2:輸入 regedit 打開註冊表3:進入 1 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\CompletionCharView Code將值改為十進位的 9 ;點擊確定4:以後運行CMD的時候... ...
  • 廢話不多說,先上效果 沒有做成安卓那種圓形的原因是...人家真的不會嘛... 好了下麵是正文: 首先在工程中引入Behavior的庫,我們使用Nuget。 在項目->引用上點擊右鍵,點擊管理Nuget程式包,然後瀏覽里搜索Microsoft.Xaml.Behaviors.Uwp.Managed 或者 ...
  • 本篇和大家分享的是一個 併發請求工具,併發往往代表的就是壓力,對於一些訂單量比較多的公司這種情況很普遍,也因此出現了很多應對併發的解決方案如:分散式,隊列,資料庫鎖等; 對於沒有遇到過或者不可能線上來處理併發問題的我們來說,需要模擬這種環境,不錯這就是寫併發請求工具的目的: . 對於api介面做併發 ...
  • 從行走江湖的世界角度來講您可以理解為一本"武功秘籍",站在我們IT編程的世界角度應該叫"開發寶典"。 如果您在工作中主要接觸的是操作MySQL資料庫,但您又想學習和瞭解.NET輕量級ORM框架Dapper,那麼就請跟著阿笨一起學習本次的分享課《.NET輕量級ORM框架Dapper葵花寶典》。Let'... ...
  • 本次的標題是我在寫單例模式的博客時遇到的問題,所以今天專門寫了的demo讓自己記住怎麼簡單的使用多線程。 一直糾結的是怎麼在for迴圈中多次實例化對象,好復現單例模式在沒有加鎖的情況下出現多個實例對象的錯誤。 先給大家看一下我簡單實現的多線程實例對象。 方案一: Demo.cs Program.cs ...
  • 為了提高網站性能,一般都會使用到緩存,緩存的數據源包括資料庫,外部介面等,緩存一般分為兩種,本地緩存和分散式緩存,這裡主要總結的是分散式緩存。 Memcached和Redis 最常用的分散式緩存是Redis和Memcached,它們都是分散式緩存技術中的一種,可能大部分的開發人員都聽說或者接觸過,但 ...
  • 今天在做測試的時候boss讓我這個菜鳥做vs2015下c#的單元測試,並且給了我參考http://www.cnblogs.com/kingmoon/archive/2011/05/13/2045278.html 但是我現在用的ide是vs2015,一般的單元測試與vs2010相同,在進行到數據驅動的 ...
  • <NET CLR via c# 第4版>個別章節雖讀過多次,但始終沒有完整讀過這本書.即使看過的那些,時間一長,也忘記了大部分.趁著最近不忙,想把這本書好好讀一遍,順便記下筆記,方便隨時查看. 真的只是筆記,因為能力有限,並不能很好地講解一個知識點,只是把我認為比較重要的地方,劃個重點,記錄到這裡. ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...