コード例 #1
0
        public ExpressionEntityValueAccessor(IEntityMetadata entity)
        {
            _entity = entity;

            var param = Expression.Parameter(typeof(object), "p");

            var isOfTypeExpression = Expression.Lambda <Func <object, bool> >(
                Expression.TypeIs(param, entity.ClrType),
                param);

            _isOfTypeDelegate = isOfTypeExpression.Compile();

            _primaryKeys = entity.GetProperties().Where(p => p.IsPrimaryKey).ToList();

            if (_primaryKeys.Count == 1)
            {
                _keyType = _primaryKeys[0].PropertyType;
            }
            else if (_primaryKeys.Count > 1)
            {
                var keyTypes = _primaryKeys.Select(p => p.PropertyType).ToArray();
                _keyType = EntityKey.Get(keyTypes);
                _createEntityKeyDelegate = GetCreateEntityKeyDelegate(_keyType);
            }

            if (_primaryKeys.Count > 0)
            {
                this._keyEqualsDelegate = GetKeyEqualsDelegate(_entity.ClrType, _primaryKeys);
            }
        }
コード例 #2
0
 public EntityMetadataBuilder Entity(Type clrType)
 {
     return(Entity(EntityKey.Get(clrType)));
 }
コード例 #3
0
 public EntityMetadataBuilder <TEntity> Entity <TEntity>()
     where TEntity : class
 {
     return(new EntityMetadataBuilder <TEntity>(Entity(EntityKey.Get <TEntity>())));
 }