Page 1 of 1

LINQ To PostGresSQL : Generic QUERY failed

Posted: Fri 24 Oct 2008 00:57
by svinfo
I tried to build a generic GetFromID query
(http://forums.thedailywtf.com/forums/t/7648.aspx) :

Code: Select all

public abstract class BllBase :  where TEntity :class
{

    protected abstract Devart.Data.Linq.DataContext ObjectContext 
   { get; }

    public TEntity EntiyGetByID(string entityKey,int entityID)
    {
            StringBuilder sql = new StringBuilder(); 
            sql.Append("SELECT ");
            MetaTable metaTable =   
                ObjectContext.Mapping.MappingSource.GetModel(
                typeof(Devart.Data.Linq.DataContext)).GetMetaType(
                        typeof(TEntity)).Table;
            
            foreach (MetaDataMember dm in 
                                MetaTable.RowType.DataMembers) 
            { 
                if (dm.DbType != null) 
                { 
                    sql.Append(dm.MappedName).Append(","); 
                } 
            } 
            sql.Remove(sql.Length - 1, 1); 
            sql.Append(" FROM ")
                .Append(metaTable.TableName)
                .Append(" WHERE ")
                .Append(entityKey)
                .Append(" = ")
                .Append(entityID);
            
                       
            try
            {
                TEntity entity = ObjectContext.ExecuteQuery
                          (sql.ToString()).FirstOrDefault();
                return entity;
            }
            catch
            {
                return null;
            }
      }
}
While the LINQ query work for a specific Entity, if I try to call the
EntiyGetByID method , it fails with the error :
{"Les types des arguments ne correspondent pas."}

==> (translate) The types of the arguments do not correspond

Do you support the ExecuteQuery(string sql ...) method ?

Posted: Tue 28 Oct 2008 08:06
by Shalex
The ExecuteQuery(string sql ...) method is not supported. Please write a SQL request using LINQ language.

Posted: Fri 21 Nov 2008 11:39
by alworks
Hello

When this function will be supported?
Without it we must write dedicated LINQ query in every class derived from base class with generic model parameter (we have about 100 classes at the moment).

Full compatibility between LINQ to SQL and LINQ to PostgreSQL is very important for us.

Thank you,
Aleksander

Posted: Fri 21 Nov 2008 13:45
by AndreyR
No timeframe can be provided for implementing this feature.
As an alternative, try to dynamically construct the System.Linq.Expression class, like in the following simple example:

Code: Select all

var q =
         from c in db.Customers
         where c.City == "dd"
         select c;
is in fact translated to

Code: Select all

IQueryable q = 
        db.Customers.Where(
            Expression.Lambda>(
                Expression.Equal(
                    Expression.Property(
                        pe = Expression.Parameter(typeof(Customer), "c"), 
                        (MethodInfo)methodof(Customer.get_City)
                    ), 
                    Expression.Constant("dd", typeof(string)), 
                    false, 
                    (MethodInfo)methodof(string.op_Equality)
                ), 
                new ParameterExpression[] { pe }
            )
        );