LINQ To PostGresSQL : Generic QUERY failed

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
svinfo
Posts: 3
Joined: Thu 23 Oct 2008 23:42

LINQ To PostGresSQL : Generic QUERY failed

Post by svinfo » Fri 24 Oct 2008 00:57

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 ?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Tue 28 Oct 2008 08:06

The ExecuteQuery(string sql ...) method is not supported. Please write a SQL request using LINQ language.

alworks
Posts: 13
Joined: Thu 20 Nov 2008 15:53

Post by alworks » Fri 21 Nov 2008 11:39

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 21 Nov 2008 13:45

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 }
            )
        );

Post Reply