示例#1
0
        public override Expression GetUpdateExpression(IMappedEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, entity, ((OTypeMapping)this.Mapping).GetTableName(entity));

            var where = this.GetIdentityCheck(table, entity, instance);
            if (updateCheck != null)
            {
                Expression typeProjector = this.GetEntityExpression(table, entity);
                Expression pred = DbExpressionReplacer.Replace(updateCheck.Body, updateCheck.Parameters[0], typeProjector);
                where = where.And(pred);
            }

            var assignments = this.GetFieldAssignments(table, instance, entity, (e, m) => ((OTypeMapping)this.Mapping).IsUpdatable(e, m));

            Expression update = new UpdateCommandExpression(table, where, assignments);

            if (selector != null)
            {
                return CreateUpdateCommand(entity, instance, selector, where, assignments);
            }
            else
            {
                return update;
            }
        }
示例#2
0
        public override void SaveBucketImport(TrelloCaseEntityBucket bucket, IMappedEntity existing, String operation)
        {
            MappedCase obj = bucket.Case;

            Case impl = cbapi.Put <Case>(obj.Local, obj.LocalID);

            bucket.Case.AddLocal(impl, impl.SyncID, impl.SyncTime);
            UpdateStatus(obj, operation);
        }
示例#3
0
        public override void MapBucketImport(TrelloCaseEntityBucket bucket, IMappedEntity existing)
        {
            MappedCase obj = bucket.Case;

            CardData data = obj.Extern;
            Case     impl = obj.Local = new Case();

            //Product
            impl.Subject     = data.Name.ValueField();
            impl.Description = data.Description.ValueField();
        }
示例#4
0
        public override Expression GetInsertExpression(IMappedEntity entity, Expression instance, LambdaExpression selector)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var table = new IdentifiableExpression(IdentifiableAlias, entity, ((OTypeMapping)this.Mapping).GetTableName(entity));
            var assignments = this.GetFieldAssignments(table, instance, entity, (e, m) => !((OTypeMapping)this.Mapping).IsGenerated(e, m));

            if (selector != null)
            {
                return CreateInsertCommand(entity, instance, selector, assignments);
            }

            return new InsertCommandExpression(table, assignments);
        }
示例#5
0
        public override EntityExpression GetEntityExpression(Expression root, IMappedEntity entity)
        {
            // must be some complex type constructed from multiple Fields
            var assignments = new List<EntityAssignment>();
            foreach (MemberInfo mi in this.mapping.GetMappedMembers(entity))
            {
                if (!this.mapping.IsAssociationRelationship(entity, mi))
                {
                    Expression me = this.GetMemberExpression(root, entity, mi);
                    if (me != null)
                    {
                        assignments.Add(new EntityAssignment(mi, me));
                    }
                }
            }

            return new EntityExpression(entity, BuildEntityExpression(entity, assignments));
        }
示例#6
0
        public override Expression GetDeleteExpression(IMappedEntity entity, Expression instance, LambdaExpression deleteCheck)
        {
            IdentifiableExpression table = new IdentifiableExpression(new IdentifiableAlias(), entity, this.mapping.GetTableName(entity));
            Expression where = null;

            if (instance != null)
            {
                where = this.GetIdentityCheck(table, entity, instance);
            }

            if (deleteCheck != null)
            {
                Expression row = this.GetEntityExpression(table, entity);
                Expression pred = DbExpressionReplacer.Replace(deleteCheck.Body, deleteCheck.Parameters[0], row);
                where = (where != null) ? where.And(pred) : pred;
            }

            return new DeleteCommandExpression(table, where);
        }
示例#7
0
 protected override Expression BuildEntityExpression(IMappedEntity entity, IList<EntityAssignment> assignments)
 {
     if (entity.EntityType.Equals(typeof(IIdentifiable))
         || entity.EntityType.Equals(typeof(IThing)))
     {
         return base.BuildEntityExpression(new OMappingEntity(typeof(_Thing), _repoType), assignments); // switch it to a constructable type
     }
     else if (entity.EntityType.Equals(typeof(IAssociation)))
     {
         return base.BuildEntityExpression(new OMappingEntity(typeof(_Association), _repoType), assignments); // switch it to a constructable type
     }
     else return base.BuildEntityExpression(entity, assignments);
 }
示例#8
0
 /// <summary>
 /// Determines if a property can be part of an update operation
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual bool IsUpdatable(IMappedEntity entity, MemberInfo member)
 {
     return !this.IsPrimaryKey(entity, member);
 }
示例#9
0
 public abstract bool IsRelationshipSource(IMappedEntity entity, MemberInfo member);
示例#10
0
 /// <summary>
 /// Determines if a property represents or is part of the entities unique identity (often primary key)
 /// </summary>
 /// <param name="member"></param>
 /// <returns></returns>
 public override bool IsPrimaryKey(IMappedEntity entity, MemberInfo member)
 {
     return false;
 }
示例#11
0
 /// <summary>
 /// Deterimines is a property is mapped onto a Field or relationship
 /// </summary>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual bool IsMapped(IMappedEntity entity, MemberInfo member)
 {
     return true;
 }
示例#12
0
 protected virtual Expression GetUpdateResult(IMappedEntity entity, Expression instance, LambdaExpression selector)
 {
     var tq = this.GetQueryExpression(entity);
     Expression where = this.GetIdentityCheck(tq.Select, entity, instance);
     Expression selection = DbExpressionReplacer.Replace(selector.Body, selector.Parameters[0], tq.Projector);
     IdentifiableAlias newAlias = new IdentifiableAlias();
     var pc = FieldProjector.ProjectFields(this.translator.Linguist.Language, selection, null, newAlias, tq.Select.Alias);
     return new ProjectionExpression(
         new SelectExpression(newAlias, pc.Fields, tq.Select, where),
         pc.Projector,
         Aggregator.GetAggregator(selector.Body.Type, typeof(IEnumerable<>).MakeGenericType(selector.Body.Type))
         );
 }
示例#13
0
 /// <summary>
 /// The name of the corresponding database table
 /// </summary>
 /// <param name="rowType"></param>
 /// <returns></returns>
 public virtual string GetTableName(IMappedEntity entity)
 {
     return entity.StorageClass;
 }
示例#14
0
 /// <summary>
 /// The query language specific type for the Field
 /// </summary>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual StorageType GetFieldType(IMappedEntity entity, MemberInfo member)
 {
     string dbType = this.mapping.GetFieldDbType(entity, member);
     if (dbType != null)
     {
         return this.translator.Linguist.Language.TypeSystem.Parse(dbType);
     }
     return this.translator.Linguist.Language.TypeSystem.GetStorageType(TypeHelper.GetMemberType(member));
 }
示例#15
0
 private bool IsNullRelationshipAssignment(IMappedEntity entity, EntityAssignment assignment)
 {
     if (this.mapping.IsRelationship(entity, assignment.Member))
     {
         var cex = assignment.Expression as ConstantExpression;
         if (cex != null && cex.Value == null)
             return true;
     }
     return false;
 }
示例#16
0
 protected virtual Expression GetIdentityCheck(Expression root, IMappedEntity entity, Expression instance)
 {
     return this.mapping.GetMappedMembers(entity)
     .Where(m => this.mapping.IsPrimaryKey(entity, m))
     .Select(m => this.GetMemberExpression(root, entity, m).Equal(Expression.MakeMemberAccess(instance, m)))
     .Aggregate((x, y) => x.And(y));
 }
示例#17
0
 /// <summary>
 /// Determines if a property is mapped onto a Field
 /// </summary>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual bool IsField(IMappedEntity entity, MemberInfo member)
 {
     //return this.mapping.IsMapped(entity, member) && this.translator.Linguist.Language.IsScalar(TypeHelper.GetMemberType(member));
     return this.IsMapped(entity, member);
 }
示例#18
0
 /// <summary>
 /// The type of the entity on the other side of the relationship
 /// </summary>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual IMappedEntity GetRelatedEntity(IMappedEntity entity, MemberInfo member)
 {
     Type relatedType = TypeHelper.GetElementType(TypeHelper.GetMemberType(member));
     return this.GetEntity(relatedType, entity.RepositoryType);
 }
示例#19
0
        protected virtual Expression GetInsertResult(IMappedEntity entity, Expression instance, LambdaExpression selector, Dictionary<MemberInfo, Expression> map)
        {
            var IdentifiableAlias = new IdentifiableAlias();
            var tex = new IdentifiableExpression(IdentifiableAlias, entity, this.mapping.GetTableName(entity));
            var aggregator = Aggregator.GetAggregator(selector.Body.Type, typeof(IEnumerable<>).MakeGenericType(selector.Body.Type));

            Expression where;
            DeclarationCommand genIdCommand = null;
            var generatedIds = this.mapping.GetMappedMembers(entity).Where(m => this.mapping.IsPrimaryKey(entity, m) && this.mapping.IsGenerated(entity, m)).ToList();
            if (generatedIds.Count > 0)
            {
                if (map == null || !generatedIds.Any(m => map.ContainsKey(m)))
                {
                    var localMap = new Dictionary<MemberInfo, Expression>();
                    genIdCommand = this.GetGeneratedIdCommand(entity, generatedIds.ToList(), localMap);
                    map = localMap;
                }

                // is this just a retrieval of one generated id member?
                var mex = selector.Body as MemberExpression;
                if (mex != null && this.mapping.IsPrimaryKey(entity, mex.Member) && this.mapping.IsGenerated(entity, mex.Member))
                {
                    if (genIdCommand != null)
                    {
                        // just use the select from the genIdCommand
                        return new ProjectionExpression(
                            genIdCommand.Source,
                            new FieldExpression(mex.Type, genIdCommand.Variables[0].QueryType, genIdCommand.Source.Alias, genIdCommand.Source.Fields[0].Name),
                            aggregator
                            );
                    }
                    else
                    {
                        IdentifiableAlias alias = new IdentifiableAlias();
                        var colType = this.GetFieldType(entity, mex.Member);
                        return new ProjectionExpression(
                            new SelectExpression(alias, new[] { new FieldDeclaration("", map[mex.Member], colType) }, null, null),
                            new FieldExpression(TypeHelper.GetMemberType(mex.Member), colType, alias, ""),
                            aggregator
                            );
                    }
                }

                where = generatedIds.Select((m, i) =>
                    this.GetMemberExpression(tex, entity, m).Equal(map[m])
                    ).Aggregate((x, y) => x.And(y));
            }
            else
            {
                where = this.GetIdentityCheck(tex, entity, instance);
            }

            Expression typeProjector = this.GetEntityExpression(tex, entity);
            Expression selection = DbExpressionReplacer.Replace(selector.Body, selector.Parameters[0], typeProjector);
            IdentifiableAlias newAlias = new IdentifiableAlias();
            var pc = FieldProjector.ProjectFields(this.translator.Linguist.Language, selection, null, newAlias, IdentifiableAlias);
            var pe = new ProjectionExpression(
                new SelectExpression(newAlias, pc.Fields, tex, where),
                pc.Projector,
                aggregator
                );

            if (genIdCommand != null)
            {
                return new BlockCommandExpression(genIdCommand, pe);
            }
            return pe;
        }
示例#20
0
 /// <summary>
 /// Determines if the property is an assocation relationship.
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual bool IsAssociationRelationship(IMappedEntity entity, MemberInfo member)
 {
     if (member.MemberType == MemberTypes.Field)
         return IsAssociationType(((FieldInfo)member).FieldType);
     else return IsAssociationType(((PropertyInfo)member).PropertyType);
 }
示例#21
0
 public override void MapBucketExport(TrelloCaseEntityBucket bucket, IMappedEntity existing)
 {
 }
示例#22
0
 /// <summary>
 /// Determines if a property is generated on the server during insert
 /// </summary>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual bool IsGenerated(IMappedEntity entity, MemberInfo member)
 {
     return false;
 }
示例#23
0
 public override void SaveBucketExport(TrelloCaseEntityBucket bucket, IMappedEntity existing, String operation)
 {
 }
示例#24
0
 public override bool IsModified(IMappedEntity entity, object instance, object original)
 {
     foreach (var mi in this.GetMappedMembers(entity))
     {
         if (this.IsField(entity, mi))
         {
             if (!object.Equals(mi.GetValue(instance), mi.GetValue(original)))
                 return true;
         }
     }
     return false;
 }
示例#25
0
 public override IEnumerable<IdentifiableInfo> GetDependingEntities(IMappedEntity entity, object instance)
 {
     foreach (var mi in this.GetMappedMembers(entity))
     {
         if (this.IsRelationship(entity, mi) && this.IsRelationshipTarget(entity, mi))
         {
             IMappedEntity relatedEntity = this.GetRelatedEntity(entity, mi);
             var value = mi.GetValue(instance);
             if (value != null)
             {
                 var list = value as IList;
                 if (list != null)
                 {
                     foreach (var item in list)
                     {
                         if (item != null)
                         {
                             yield return new IdentifiableInfo(item, relatedEntity);
                         }
                     }
                 }
                 else
                 {
                     yield return new IdentifiableInfo(value, relatedEntity);
                 }
             }
         }
     }
 }
示例#26
0
 public override bool IsRelationship(IMappedEntity entity, MemberInfo member)
 {
     return this.IsAssociationRelationship(entity, member);
 }
示例#27
0
 /// <summary>
 /// The type declaration for the Field in the provider's syntax
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="member"></param>
 /// <returns>a string representing the type declaration or null</returns>
 public virtual string GetFieldDbType(IMappedEntity entity, MemberInfo member)
 {
     return null;
 }
示例#28
0
 public abstract bool IsRelationshipTarget(IMappedEntity entity, MemberInfo member);
示例#29
0
 /// <summary>
 /// The name of the corresponding table Field
 /// </summary>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual string GetFieldName(IMappedEntity entity, MemberInfo member)
 {
     return member.Name;
 }
示例#30
0
 /// <summary>
 /// Returns the key members on this side of the association
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="member"></param>
 /// <returns></returns>
 public virtual IEnumerable<MemberInfo> GetAssociationKeyMembers(IMappedEntity entity, MemberInfo member)
 {
     return new MemberInfo[] { };
 }
示例#31
0
 /// <summary>
 /// A sequence of all the mapped members
 /// </summary>
 /// <param name="rowType"></param>
 /// <returns></returns>
 public override IEnumerable<MemberInfo> GetMappedMembers(IMappedEntity entity)
 {
     //Type type = entity.ElementType.IsInterface ? entity.EntityType : entity.ElementType;
     Type type = entity.EntityType;
     HashSet<MemberInfo> members = new HashSet<MemberInfo>(type.GetFields().Cast<MemberInfo>().Where(m => this.IsMapped(entity, m)));
     members.UnionWith(type.GetProperties().Cast<MemberInfo>().Where(m => this.IsMapped(entity, m)));
     return members.OrderBy(m => m.Name);
 }
示例#32
0
        private OUpdateCommandExpression CreateUpdateCommand(IMappedEntity entity, 
            Expression instance, LambdaExpression selector, Expression where, IEnumerable<FieldAssignment> assignments)
        {
            var identifiableAlias = new IdentifiableAlias();
            var tex = new IdentifiableExpression(identifiableAlias, entity, ((OTypeMapping)this.Mapping).GetTableName(entity));
            Expression typeProjector = this.GetEntityExpression(tex, entity);
            Expression selection = DbExpressionReplacer.Replace(selector.Body, selector.Parameters[0], typeProjector);
            IdentifiableAlias newAlias = new IdentifiableAlias();
            var pc = FieldProjector.ProjectFields(this.Translator.Linguist.Language, selection, null, newAlias, identifiableAlias);

            return new OUpdateCommandExpression(tex, where, assignments, pc.Projector);
        }
示例#33
0
 public override object GetPrimaryKey(IMappedEntity entity, object instance)
 {
     object firstKey = null;
     List<object> keys = null;
     foreach (var mi in this.GetPrimaryKeyMembers(entity))
     {
         if (firstKey == null)
         {
             firstKey = mi.GetValue(instance);
         }
         else
         {
             if (keys == null)
             {
                 keys = new List<object>();
                 keys.Add(firstKey);
             }
             keys.Add(mi.GetValue(instance));
         }
     }
     if (keys != null)
     {
         return new CompoundKey(keys.ToArray());
     }
     return firstKey;
 }
示例#34
0
        public override Expression GetPrimaryKeyQuery(IMappedEntity entity, Expression source, Expression[] keys)
        {
            // make predicate
            ParameterExpression p = Expression.Parameter(entity.EntityType, "p");
            Expression pred = null;
            var idMembers = this.GetPrimaryKeyMembers(entity).ToList();
            if (idMembers.Count != keys.Length)
            {
                throw new InvalidOperationException("Incorrect number of primary key values");
            }
            for (int i = 0, n = keys.Length; i < n; i++)
            {
                MemberInfo mem = idMembers[i];
                Type memberType = TypeHelper.GetMemberType(mem);
                if (keys[i] != null && TypeHelper.GetNonNullableType(keys[i].Type) != TypeHelper.GetNonNullableType(memberType))
                {
                    throw new InvalidOperationException("Primary key value is wrong type");
                }
                Expression eq = Expression.MakeMemberAccess(p, mem).Equal(keys[i]);
                pred = (pred == null) ? eq : pred.And(eq);
            }
            var predLambda = Expression.Lambda(pred, p);

            return Expression.Call(typeof(Queryable), "SingleOrDefault", new Type[] { entity.EntityType }, source, predLambda);
        }
示例#35
0
 public ConcreteEntityWithDependancyInjection(IMappedEntity typeToResolve)
 {
 }