示例#1
0
        JoinBuilder<T, TRelation> BuildJoinBuilder<TRelation>(JoinType joinType)
        {
            JoinBuilder jbuilder = new JoinBuilder(innerBuilder, Table.TableName, null, null);
            var map = GetMapConfig();

            EntityMap joinMap = map.GetEntityMap(typeof(TRelation).FullName);

            var count = Table.Relations.Count;
            if (Table.IsSubClass)
                count = count + 1;

            var prefix = TableQueryMap.CreatePrefix(count + 1, 2);

            switch (joinType)
            {
                case JoinType.Inner:
                    innerBuilder.InnerJoin(joinMap.TableName, prefix);
                    break;
                case JoinType.Full:
                    break;
                case JoinType.Left:
                    innerBuilder.LeftJoin(joinMap.TableName, prefix);
                    break;
                case JoinType.Right:
                    innerBuilder.RightJoin(joinMap.TableName, prefix);
                    break;
            }
            return new JoinBuilder<T, TRelation>(this, jbuilder, joinMap);
        }
示例#2
0
        void AddColumnAndParameterToUpdateInfo(UpdateSqlExecutionList execList, UpdateSqlBodyInfo updateBodyInfo, EntityMap entityMap, Property prop, PropertyAccessor propInfo, EntityAccessor accessor)
        {
            object val   = propInfo.GetMethod(entity);
            bool   isRel = false;

            if (prop is Relation)
            {
                var rel = (Relation)prop;
                if (updateBodyInfo.Columns.ContainsKey(prop.ColumnName))
                {
                    return;
                }

                isRel = true;
                if (val != null)
                {
                    if (rel.RelationType == RelationshipType.ManyToOne)
                    {
                        var store       = new EntityAccessorStore();
                        var relMap      = session.SessionFactory.DbSettings.Map.GetEntityMap(rel.ReferenceEntityName);
                        var relAccessor = store.GetEntityAccessor(val.GetType(), relMap);

                        var relPinfo = relAccessor.Properties[rel.ReferenceProperty];

                        if (relPinfo == null)
                        {
                            throw new MappingException(string.Format("could not find property {0} in mapped entity {1}", rel.ReferenceProperty, relMap.FullName));
                        }

                        val = relPinfo.GetMethod(val);
                    }
                    else if (rel.RelationType == RelationshipType.ManyToMany)
                    {
                        var trackableCollection = val as ITrackableCollection;
                        if (trackableCollection != null)
                        {
                            AddInsertManyToManyOperation(execList, trackableCollection.InsertedItems, rel, accessor, true);
                            AddInsertManyToManyOperation(execList, trackableCollection.DeletedItems, rel, accessor, false);
                        }
                        return;
                        //NOTE: if not trackable collection used mapped statement to add or remove many to many associations
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                Tuple <QueryParam, bool> etuple;
                if (updateBodyInfo.Columns.TryGetValue(prop.ColumnName, out etuple))
                {
                    if (etuple.Item2)
                    {
                        updateBodyInfo.Columns.Remove(prop.ColumnName);
                    }
                    else
                    {
                        return;
                    }
                }
            }

            //Tuple<QueryParam, bool> tuple = Tuple.Create(new QueryParam(string.Format("{0}_{1}",entityMap.TableAlias, prop.ColumnName)) { Value = val }, isRel);
            Tuple <QueryParam, bool> tuple = Tuple.Create(QueryParam.CreateParameter(prop, string.Format("{0}_{1}", TableQueryMap.CreatePrefix(2, 2), prop.ColumnName), val), isRel);

            updateBodyInfo.Columns.Add(prop.ColumnName, tuple);
        }