Exemple #1
0
        private void AddJoin(Expression expression, SGBD.Sgbd.Join join)
        {
            try
            {
                if (expression is MemberExpression)
                {
                    MemberExpression operand      = expression as MemberExpression;
                    string           propertyName = operand.Member.Name;
                    System.Type[]    arguments    = this.GetType().GetGenericArguments();
                    if (arguments.Length > 0)
                    {
                        System.Type  table   = arguments[0];
                        PropertyInfo colonne = table.GetProperty(propertyName);
                        if (colonne.GetCustomAttribute(typeof(JoinColumn)) != null)
                        {
                            string tableName   = DataBase.SGBD.TableName(table);
                            string colonneName = tableName + "." + DataBase.SGBD.ColonnName(colonne);
                            string liaison     = " inner join ";
                            switch (join)
                            {
                            case SGBD.Sgbd.Join.LEFT:
                                liaison = " left join ";
                                break;

                            case SGBD.Sgbd.Join.RIGHT:
                                liaison = " right join ";
                                break;
                            }
                            string referenceTable = DataBase.SGBD.TableName(colonne.PropertyType);
                            string referenceName  = referenceTable + "." + DataBase.SGBD.ReferenceName(colonne);
                            liaison   += referenceTable + " " + referenceTable + " on " + colonneName + " = " + referenceName;
                            this.join += liaison;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #2
0
 public DbSet <T> Join(Expression <Func <T, Object> > expression, SGBD.Sgbd.Join join)
 {
     try
     {
         if (expression.Body is MemberExpression)
         {
             MemberExpression operand = expression.Body as MemberExpression;
             AddJoin(operand, join);
         }
         else if (expression.Body is NewExpression)
         {
             NewExpression lbex = expression.Body as NewExpression;
             foreach (Expression argument in lbex.Arguments)
             {
                 AddJoin(argument, join);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return(this);
 }