Exemple #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Table{TEntity, TPrimaryKey}"/>
        ///     class.
        /// </summary>
        /// <param name="database"> The database. </param>
        /// <param name="primaryKey"> The primary key. </param>
        /// <param name="identitySpecification"> The identity specification. </param>
        public Table(
            IDatabase database,
            IKeyInfo <TEntity, TPrimaryKey> primaryKey,
            IdentitySpecification <TEntity> identitySpecification)

            : base(database, false)
        {
            this.VerifyType();

            this.id = Interlocked.Increment(ref counter);

            this.indexes       = new List <IIndex <TEntity> >();
            this.constraints   = new ConstraintCollection <TEntity>();
            this.entityService = database
                                 .DatabaseEngine
                                 .ServiceProvider
                                 .GetService <IEntityService>();

            this.primaryKeyIndex =
                this.CreateUniqueIndex(new DictionaryIndexFactory(), primaryKey);

            this.RegisterTimestampConstraints();

            if (identitySpecification != null)
            {
                this.identityField = new IdentityField <TEntity>(identitySpecification);
            }
        }
Exemple #2
0
        public DefaultTable(
            IDatabase database,
            IKeyInfo <TEntity, TPrimaryKey> primaryKey,
            IdentitySpecification <TEntity> identitySpecification)

            : base(database, primaryKey, identitySpecification)
        {
        }
Exemple #3
0
        public DefaultTable(
            IDatabase database,
            IKeyInfo <TEntity, TPrimaryKey> primaryKey,
            IdentitySpecification <TEntity> identitySpecification,
            object tableInfo = null)

            : base(database, primaryKey, identitySpecification, tableInfo)
        {
        }
Exemple #4
0
        internal IdentityField(IdentitySpecification <TEntity> identitySpecification)
        {
            this.identitySpecification = identitySpecification;

            this.nextIdentity = this.identitySpecification.Seed;

            MemberExpression member       = ExpressionHelper.FindMemberExpression(identitySpecification.IdentityColumn.Body);
            PropertyInfo     identityInfo = member.Member as PropertyInfo;

            this.identityType   = identityInfo.PropertyType;
            this.identitySetter = DynamicMethodBuilder.CreatePropertySetter <TEntity>(identityInfo);
            this.identityGetter = this.identitySpecification.IdentityColumn.Compile();
        }
Exemple #5
0
        /// <summary>
        ///     Initializes a database table.
        /// </summary>
        /// <typeparam name="TEntity">
        ///     Specifies the type of the entities of the table.
        /// </typeparam>
        /// <typeparam name="TPrimaryKey">
        ///     Specifies the type of the primary key of the entities.
        /// </typeparam>
        /// <param name="primaryKey">
        ///     An expression that represents the primary key of the entities.
        /// </param>
        /// <param name="identitySpecification">
        ///     An IdentitySpecification to set an identity field.
        /// </param>
        /// <returns>
        ///     An Table that represents the defined table object.
        /// </returns>
        public Table <TEntity, TPrimaryKey> Create <TEntity, TPrimaryKey>(
            Expression <Func <TEntity, TPrimaryKey> > primaryKey,
            IdentitySpecification <TEntity> identitySpecification)

            where TEntity : class
        {
            if (primaryKey == null)
            {
                throw new ArgumentNullException("primaryKey");
            }

            IKeyInfoFactory keyInfoFactory = new ModularKeyInfoFactory(this.database);

            return(this.Create(keyInfoFactory.Create(primaryKey), identitySpecification));
        }
Exemple #6
0
        /// <summary>
        ///     Initializes a database table.
        /// </summary>
        /// <typeparam name="TEntity">
        ///     Specifies the type of the entities of the table.
        ///  </typeparam>
        /// <typeparam name="TPrimaryKey">
        ///     Specifies the type of the primary key of the entities.
        ///  </typeparam>
        /// <param name="primaryKey">
        ///     An IKeyInfo object that represents the primary key of the entities.
        /// </param>
        /// <param name="identitySpecification">
        ///     An IdentitySpecification to set an identity field.
        /// </param>
        /// <returns>
        ///     The table.
        /// </returns>
        public Table <TEntity, TPrimaryKey> Create <TEntity, TPrimaryKey>(
            IKeyInfo <TEntity, TPrimaryKey> primaryKey,
            IdentitySpecification <TEntity> identitySpecification,
            object tableInfo = null)

            where TEntity : class
        {
            if (primaryKey == null)
            {
                throw new ArgumentNullException("primaryKey");
            }

            ITableService service = this.database
                                    .DatabaseEngine
                                    .ServiceProvider
                                    .GetService <ITableService>();

            if (service == null)
            {
                throw new NMemoryException(ExceptionMessages.ServiceNotFound, "TableService");
            }

            Table <TEntity, TPrimaryKey> table =
                service.CreateTable <TEntity, TPrimaryKey>(
                    primaryKey,
                    identitySpecification,
                    this.database,
                    tableInfo);

            if (table == null)
            {
                throw new NMemoryException(ExceptionMessages.TableNotCreated);
            }

            this.RegisterTable(table);

            return(table);
        }