Пример #1
0
 public EntityPersister(InternalContext context)
 {
     this.context        = context;
     Database            = context.Database;
     entityQueryProvider = new EntityQueryProvider(context);
     queryable           = new QueryProvider(entityQueryProvider);
     environment         = context.Environment;
 }
Пример #2
0
 /// <summary>
 /// 使用 <see cref="IDatabase"/> 对象初始化 <see cref="T:Lord.Data.Entity.EntityPersister`1"/> 类的新实例。
 /// </summary>
 /// <param name="database">一个 <see cref="IDatabase"/> 对象。</param>
 public EntityPersister(IDatabase database)
 {
     Database            = database;
     context             = new InternalContext(database);
     entityQueryProvider = new EntityQueryProvider(context);
     queryable           = new QueryProvider(entityQueryProvider);
     environment         = context.Environment;
 }
        /// <summary>
        /// 使用持久化环境进行分表配置。
        /// </summary>
        /// <param name="setupAction">对 <see cref="EntityPersistentEnvironment"/> 进行配置的方法。</param>
        /// <returns></returns>
        public EntityContextOptionsBuilder UseEnvironment(Action <EntityPersistentEnvironment> setupAction)
        {
            var environment = new EntityPersistentEnvironment();

            setupAction?.Invoke(environment);
            Options.Initializers.Add <EnvironmentPreInitializer>(s => s.Environment = environment);
            return(this);
        }
Пример #4
0
 /// <summary>
 /// 使用实例名初始化 <see cref="T:Lord.Data.Entity.EntityPersister`1"/> 类的新实例。
 /// </summary>
 /// <param name="instanceName">实例名。</param>
 public EntityPersister(string instanceName = null)
 {
     metadata            = EntityMetadataUnity.GetEntityMetadata(GetEntityType());
     context             = new InternalContext(instanceName);
     Database            = context.Database;
     entityQueryProvider = new EntityQueryProvider(context);
     queryable           = new QueryProvider(entityQueryProvider);
     entityQueryProvider.InitializeInstanceName(instanceName);
     environment = context.Environment;
 }
Пример #5
0
        /// <summary>
        /// 如果对象实现了 <see cref="IEntityPersistentEnvironment"/> 接口,则会将 <paramref name="environment"/> 附加到该对象;
        /// </summary>
        /// <param name="item"></param>
        /// <param name="environment"></param>
        internal static T InitializeEnvironment <T>(this T item, EntityPersistentEnvironment environment)
        {
            if (item == null)
            {
                return(default(T));
            }

            item.As <IEntityPersistentEnvironment>(e =>
            {
                if (environment != null)
                {
                    e.Environment = environment;
                }
            });

            return(item);
        }
Пример #6
0
 /// <summary>
 /// 初始化 <see cref="EntityPersisterHelper"/> 类的新实例。
 /// </summary>
 /// <param name="database">提供给持久化操作的 <see cref="Database"/> 对象。</param>
 /// <param name="entityType">实体的类型。</param>
 /// <param name="environment">实体持久化环境对象。</param>
 public EntityPersisterHelper(IDatabase database, Type entityType, EntityPersistentEnvironment environment)
 {
     this.database    = database;
     this.entityType  = entityType;
     this.environment = environment;
 }