Exemplo n.º 1
0
        private static ResolvedJoinInfo CreateResolvedJoinInfo(
            SqlEntityExpression originatingEntity, MetaAssociation metaAssociation, IResolvedTableInfo joinedTableInfo)
        {
            var leftColumn = ResolveMember(originatingEntity, metaAssociation.ThisKey);

            // If needed, implement by using compounds (NewExpressions with named arguments, see NamedExpression.CreateNewExpressionWithNamedArguments.)
            if (metaAssociation.OtherKey.Count > 1)
            {
                throw new NotSupportedException(
                          string.Format(
                              "Associations with more than one column are currently not supported. ({0}.{1})",
                              originatingEntity.Type,
                              metaAssociation.OtherMember.Name));
            }

            var otherKey    = metaAssociation.OtherKey[0];
            var rightColumn = new SqlColumnDefinitionExpression(
                otherKey.Type,
                joinedTableInfo.TableAlias,
                otherKey.MappedName,
                otherKey.IsPrimaryKey);

            var joinCondition = ConversionUtility.MakeBinaryWithOperandConversion(ExpressionType.Equal, leftColumn, rightColumn, false, null);

            return(new ResolvedJoinInfo(joinedTableInfo, joinCondition));
        }
Exemplo n.º 2
0
 private static SqlColumnExpression CreateSqlColumnExpression(IResolvedTableInfo tableInfo, MetaDataMember metaDataMember)
 {
     return(new SqlColumnDefinitionExpression(
                metaDataMember.Type,
                tableInfo.TableAlias,
                metaDataMember.MappedName,
                metaDataMember.IsPrimaryKey));
 }
Exemplo n.º 3
0
        public SqlEntityDefinitionExpression ResolveSimpleTableInfo(IResolvedTableInfo tableInfo, UniqueIdentifierGenerator generator)
        {
            ArgumentUtility.CheckNotNull("tableInfo", tableInfo);
            ArgumentUtility.CheckNotNull("generator", generator);

            var classDefinition = GetClassDefinition(tableInfo.ItemType);

            return(_storageSpecificExpressionResolver.ResolveEntity(classDefinition, tableInfo.TableAlias));
        }
    public ResolvedJoinInfo (IResolvedTableInfo foreignTableInfo, Expression joinCondition)
    {
      ArgumentUtility.CheckNotNull ("foreignTableInfo", foreignTableInfo);
      ArgumentUtility.CheckNotNull ("joinCondition", joinCondition);

      if (!BooleanUtility.IsBooleanType (joinCondition.Type))
        throw new ArgumentException ("The join condition must have boolean (or nullable boolean) type.", "joinCondition");
      
      _foreignTableInfo = foreignTableInfo;
      _joinCondition = joinCondition;
    }
Exemplo n.º 5
0
        public ResolvedJoinInfo(IResolvedTableInfo foreignTableInfo, Expression joinCondition)
        {
            ArgumentUtility.CheckNotNull("foreignTableInfo", foreignTableInfo);
            ArgumentUtility.CheckNotNull("joinCondition", joinCondition);

            if (!BooleanUtility.IsBooleanType(joinCondition.Type))
            {
                throw new ArgumentException("The join condition must have boolean (or nullable boolean) type.", "joinCondition");
            }

            _foreignTableInfo = foreignTableInfo;
            _joinCondition    = joinCondition;
        }
Exemplo n.º 6
0
        public ResolvedJoinInfo ResolveJoinInfo(UnresolvedJoinInfo joinInfo, UniqueIdentifierGenerator generator)
        {
            ArgumentUtility.CheckNotNull("joinInfo", joinInfo);
            ArgumentUtility.CheckNotNull("generator", generator);

            var metaType        = GetMetaType(joinInfo.OriginatingEntity.Type);
            var metaAssociation = GetDataMember(metaType, joinInfo.MemberInfo).Association;

            Assertion.DebugAssert(metaAssociation != null);

            IResolvedTableInfo resolvedTable = ResolveTableInfo(new UnresolvedTableInfo(joinInfo.ItemType), generator);

            return(CreateResolvedJoinInfo(joinInfo.OriginatingEntity, metaAssociation, resolvedTable));
        }
        private ResolvedJoinInfo CreateResolvedJoinInfo(
            SqlEntityExpression originatingEntity,
            string leftColumnName,
            Type leftColumnType,
            bool leftColumnIsPrimaryKey,
            IResolvedTableInfo joinedTableInfo,
            string rightColumnName,
            Type rightColumnType,
            bool rightColumnIsPrimaryKey)
        {
            var leftColumn  = originatingEntity.GetColumn(leftColumnType, leftColumnName, leftColumnIsPrimaryKey);
            var rightColumn = CreateColumn(rightColumnType, joinedTableInfo.TableAlias, rightColumnName, rightColumnIsPrimaryKey);

            return(new ResolvedJoinInfo(
                       joinedTableInfo, ConversionUtility.MakeBinaryWithOperandConversion(ExpressionType.Equal, leftColumn, rightColumn, false, null)));
        }
Exemplo n.º 8
0
        public SqlEntityDefinitionExpression ResolveSimpleTableInfo(IResolvedTableInfo tableInfo, UniqueIdentifierGenerator generator)
        {
            ArgumentUtility.CheckNotNull("tableInfo", tableInfo);
            ArgumentUtility.CheckNotNull("generator", generator);

            Type type = tableInfo.ItemType;
            var  primaryKeyMembers = GetMetaType(type).IdentityMembers;

            var columnMembers = GetMetaDataMembers(tableInfo.ItemType);

            var columns = columnMembers.Select(metaDataMember => CreateSqlColumnExpression(tableInfo, metaDataMember)).ToArray();

            return(new SqlEntityDefinitionExpression(
                       tableInfo.ItemType,
                       tableInfo.TableAlias,
                       null,
                       e => CreateIdentityExpression(type, primaryKeyMembers.Select(m => ResolveDataMember(e, m)).ToArray()),
                       columns));
        }
        public virtual SqlEntityDefinitionExpression ResolveSimpleTableInfo(
            IResolvedTableInfo tableInfo, UniqueIdentifierGenerator generator)
        {
            Type type = tableInfo.ItemType;

            if (type == typeof(Cook))
            {
                return(new SqlEntityDefinitionExpression(
                           tableInfo.ItemType,
                           tableInfo.TableAlias, null,
                           e => e.GetColumn(typeof(int), "ID", true),
                           new[]
                {
                    CreateColumn(typeof(int), tableInfo.TableAlias, "ID", true),
                    CreateColumn(typeof(string), tableInfo.TableAlias, "FirstName", false),
                    CreateColumn(typeof(string), tableInfo.TableAlias, "Name", false),
                    CreateColumn(typeof(bool), tableInfo.TableAlias, "IsStarredCook", false),
                    CreateColumn(typeof(bool), tableInfo.TableAlias, "IsFullTimeCook", false),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "SubstitutedID", false),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "KitchenID", false),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "KnifeID", false),
                    CreateColumn(typeof(string), tableInfo.TableAlias, "KnifeClassID", false)
                }));
            }
            else if (type == typeof(Kitchen))
            {
                return(new SqlEntityDefinitionExpression(
                           tableInfo.ItemType,
                           tableInfo.TableAlias, null,
                           e => e.GetColumn(typeof(int), "ID", true),
                           new[]
                {
                    CreateColumn(typeof(int), tableInfo.TableAlias, "ID", true),
                    CreateColumn(typeof(string), tableInfo.TableAlias, "Name", false),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "RestaurantID", false),
                    CreateColumn(typeof(DateTime?), tableInfo.TableAlias, "LastCleaningDay", false),
                    CreateColumn(typeof(bool?), tableInfo.TableAlias, "PassedLastInspection", false),
                    CreateColumn(typeof(int?), tableInfo.TableAlias, "LastInspectionScore", false)
                }));
            }
            else if (type == typeof(Restaurant))
            {
                return(new SqlEntityDefinitionExpression(
                           tableInfo.ItemType,
                           tableInfo.TableAlias, null,
                           e => e.GetColumn(typeof(int), "ID", true),
                           new[]
                {
                    CreateColumn(typeof(int), tableInfo.TableAlias, "ID", true),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "CompanyID", false)
                }));
            }
            else if (type == typeof(Chef))
            {
                return(new SqlEntityDefinitionExpression(
                           tableInfo.ItemType,
                           tableInfo.TableAlias, null,
                           e => e.GetColumn(typeof(int), "ID", true),
                           new[]
                {
                    CreateColumn(typeof(int), tableInfo.TableAlias, "ID", true),
                    CreateColumn(typeof(string), tableInfo.TableAlias, "FirstName", false),
                    CreateColumn(typeof(string), tableInfo.TableAlias, "Name", false),
                    CreateColumn(typeof(bool), tableInfo.TableAlias, "IsStarredCook", false),
                    CreateColumn(typeof(bool), tableInfo.TableAlias, "IsFullTimeCook", false),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "SubstitutedID", false),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "KitchenID", false),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "KnifeID", false),
                    CreateColumn(typeof(int), tableInfo.TableAlias, "KnifeClassID", false),
                    CreateColumn(typeof(string), tableInfo.TableAlias, "LetterOfRecommendation", false)
                }));
            }
            else if (type == typeof(Company))
            {
                return(new SqlEntityDefinitionExpression(
                           tableInfo.ItemType,
                           tableInfo.TableAlias, null,
                           e => e.GetColumn(typeof(int), "ID", true),
                           new[]
                {
                    CreateColumn(typeof(int), tableInfo.TableAlias, "ID", true),
                    CreateColumn(typeof(DateTime), tableInfo.TableAlias, "DateOfIncorporation", false)
                }));
            }
            else if (type == typeof(Knife))
            {
                return(new SqlEntityDefinitionExpression(
                           tableInfo.ItemType,
                           tableInfo.TableAlias, null,
                           e => CreateMetaIDExpression(e.GetColumn(typeof(int), "ID", true), e.GetColumn(typeof(string), "ClassID", true)),
                           new[]
                {
                    CreateColumn(typeof(int), tableInfo.TableAlias, "ID", true),
                    CreateColumn(typeof(string), tableInfo.TableAlias, "ClassID", true),
                    CreateColumn(typeof(double), tableInfo.TableAlias, "Sharpness", false)
                }));
            }
            throw new UnmappedItemException(string.Format("Type '{0}' is not supported by the MappingResolverStub.", type.Name));
        }
    private ResolvedJoinInfo CreateResolvedJoinInfo (
        SqlEntityExpression originatingEntity,
        string leftColumnName,
        Type leftColumnType,
        bool leftColumnIsPrimaryKey,
        IResolvedTableInfo joinedTableInfo,
        string rightColumnName,
        Type rightColumnType,
        bool rightColumnIsPrimaryKey)
    {
      var leftColumn = originatingEntity.GetColumn (leftColumnType, leftColumnName, leftColumnIsPrimaryKey);
      var rightColumn = CreateColumn (rightColumnType, joinedTableInfo.TableAlias, rightColumnName, rightColumnIsPrimaryKey);

      return new ResolvedJoinInfo (
          joinedTableInfo, ConversionUtility.MakeBinaryWithOperandConversion (ExpressionType.Equal, leftColumn, rightColumn, false, null));
    }
 public virtual SqlEntityDefinitionExpression ResolveSimpleTableInfo (
     IResolvedTableInfo tableInfo, UniqueIdentifierGenerator generator)
 {
   Type type = tableInfo.ItemType;
   if (type == typeof (Cook))
   {
     return new SqlEntityDefinitionExpression (
         tableInfo.ItemType,
         tableInfo.TableAlias, null,
         e => e.GetColumn (typeof (int), "ID", true),
         new[]
         {
             CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
             CreateColumn (typeof (string), tableInfo.TableAlias, "FirstName", false),
             CreateColumn (typeof (string), tableInfo.TableAlias, "Name", false),
             CreateColumn (typeof (bool), tableInfo.TableAlias, "IsStarredCook", false),
             CreateColumn (typeof (bool), tableInfo.TableAlias, "IsFullTimeCook", false),
             CreateColumn (typeof (int), tableInfo.TableAlias, "SubstitutedID", false),
             CreateColumn (typeof (int), tableInfo.TableAlias, "KitchenID", false),
             CreateColumn (typeof (int), tableInfo.TableAlias, "KnifeID", false),
             CreateColumn (typeof (string), tableInfo.TableAlias, "KnifeClassID", false)
         });
   }
   else if (type == typeof (Kitchen))
   {
     return new SqlEntityDefinitionExpression (
         tableInfo.ItemType,
         tableInfo.TableAlias, null,
         e => e.GetColumn (typeof (int), "ID", true),
         new[]
         {
             CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
             CreateColumn (typeof (string), tableInfo.TableAlias, "Name", false),
             CreateColumn (typeof (int), tableInfo.TableAlias, "RestaurantID", false),
             CreateColumn (typeof (DateTime?), tableInfo.TableAlias, "LastCleaningDay", false),
             CreateColumn (typeof (bool?), tableInfo.TableAlias, "PassedLastInspection", false),
             CreateColumn (typeof (int?), tableInfo.TableAlias, "LastInspectionScore", false)
         });
   }
   else if (type == typeof (Restaurant))
   {
     return new SqlEntityDefinitionExpression (
         tableInfo.ItemType,
         tableInfo.TableAlias, null,
         e => e.GetColumn (typeof (int), "ID", true),
         new[]
         {
             CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
             CreateColumn (typeof (int), tableInfo.TableAlias, "CompanyID", false)
         });
   }
   else if (type == typeof (Chef))
   {
     return new SqlEntityDefinitionExpression (
         tableInfo.ItemType,
         tableInfo.TableAlias, null,
         e => e.GetColumn (typeof (int), "ID", true),
         new[]
         {
             CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
             CreateColumn (typeof (string), tableInfo.TableAlias, "FirstName", false),
             CreateColumn (typeof (string), tableInfo.TableAlias, "Name", false),
             CreateColumn (typeof (bool), tableInfo.TableAlias, "IsStarredCook", false),
             CreateColumn (typeof (bool), tableInfo.TableAlias, "IsFullTimeCook", false),
             CreateColumn (typeof (int), tableInfo.TableAlias, "SubstitutedID", false),
             CreateColumn (typeof (int), tableInfo.TableAlias, "KitchenID", false),
             CreateColumn (typeof (int), tableInfo.TableAlias, "KnifeID", false),
             CreateColumn (typeof (int), tableInfo.TableAlias, "KnifeClassID", false),
             CreateColumn (typeof (string), tableInfo.TableAlias, "LetterOfRecommendation", false)
         });
   }
   else if (type == typeof (Company))
   {
     return new SqlEntityDefinitionExpression (
         tableInfo.ItemType,
         tableInfo.TableAlias, null,
         e => e.GetColumn (typeof (int), "ID", true),
         new[]
         {
             CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
             CreateColumn (typeof (DateTime), tableInfo.TableAlias, "DateOfIncorporation", false)
         });
   }
   else if (type == typeof (Knife))
   {
     return new SqlEntityDefinitionExpression (
         tableInfo.ItemType,
         tableInfo.TableAlias, null,
         e => CreateMetaIDExpression (e.GetColumn (typeof (int), "ID", true), e.GetColumn (typeof (string), "ClassID", true)),
         new[]
         {
             CreateColumn (typeof (int), tableInfo.TableAlias, "ID", true),
             CreateColumn (typeof (string), tableInfo.TableAlias, "ClassID", true),
             CreateColumn (typeof (double), tableInfo.TableAlias, "Sharpness", false)
         });
   }
   throw new UnmappedItemException (string.Format ("Type '{0}' is not supported by the MappingResolverStub.", type.Name));
 }