Exception when using Where and Count extension methods

Exception when using Where and Count extension methods

Postby freakshow » Wed 14 Jan 2009 15:17

dotConnect version: 5.00.16, Oracle db

Getting exceptions when doing basic Linq queries.

Code to reproduce the errors:
Code: Select all
using System;
using System.Data.Linq.Mapping;
using System.Linq;
using Devart.Data.Linq;


namespace DevartTest
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
            1. Create a console application
            2. Make sure project references DevArt.Data.Linq, DevArt.Data.Oracle, etc...
            3. Change connectionstring below
            4. Run Oracle create script for test table:
             
            CREATE TABLE EMPLOYEE ("ID" NUMBER NOT NULL ENABLE, "NAME" NVARCHAR2(50));
            INSERT INTO EMPLOYEE (ID, NAME) VALUES (1, 'John Johnson');
            INSERT INTO EMPLOYEE (ID, NAME) VALUES (2, 'Jane Doe');
            COMMIT;

           
             */
            using (EntityContext ctx = new EntityContext())
            {
                // All the scenarios below works with Linq to Sql,


                // Scenario 1, Normal LINQ query with a where critera: Works
                Table empTable1 = ctx.GetTable();
                var qry1 = empTable1.Where(em => em.Id > 0);

                foreach (var employee in qry1)
                {
                    Console.WriteLine(employee.Id);
                }


                // Scenario 2, Normal LINQ query with a where critera: Exception
                Table empTable2 = ctx.GetTable();
                var qry2a = empTable2.Cast();
                var qry2b = qry2a.Where(em => 1==1); // works with an expression that does not use the em variable
                var qry2c = qry2a.Where(em => em.Id > 0); // does not work since expression uses the em variable

                foreach (var employee in qry2b)
                {
                    Console.WriteLine(employee.Id);
                }

                foreach (var employee in qry2c)
                {
                    Console.WriteLine(employee.Id);
                }

                // Scenario 3, Normal LINQ query with count: Exception
                Table empTable3 = ctx.GetTable();
                int count1 = empTable3.Count();
               
                Console.WriteLine(count1);

                // Scenario 4, Normal LINQ query with count (where table is casted to interface): Exception
                Table empTable4 = ctx.GetTable();
                IQueryable empTable5 = empTable4.Cast();

                int count2 = empTable5.Count();

                Console.WriteLine(count2);

            }

            Console.ReadKey();
        }

        [Provider(typeof(Devart.Data.Oracle.Linq.Provider.OracleDataProvider))]
        public class EntityContext : Devart.Data.Linq.DataContext
        {
            public EntityContext()
                : base("User Id=xx;Password=xx;Server=xx;Direct=True;Sid=xx") { }
        }

        public interface IEmployee
        {
            int Id { get; set; }
            string Name { get; set; }
        }

        [Table(Name = "EMPLOYEE")]
        public class Employee : IEmployee
        {
            [Column(Name = "ID", IsPrimaryKey = true)]
            public int Id { get; set; }

            [Column(Name = "NAME")]
            public string Name { get; set; }
        }
    }
}



See also previously similar reported errors: http://devart.com/forums/viewtopic.php?t=13619
freakshow
 
Posts: 12
Joined: Mon 28 Jul 2008 12:38
Location: Oslo, Norway

Postby AndreyR » Wed 14 Jan 2009 16:27

Thank you for the report, we have reproduced these problems also. I will let you know about the results of our investigation.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Postby AndreyR » Wed 21 Jan 2009 10:03

Try using the EntityContext constructor with MappingSource, like the following:
Code: Select all
    [Provider(typeof(Devart.Data.Oracle.Linq.Provider.OracleDataProvider))]
    public class EntityContext : Devart.Data.Linq.DataContext {
     
      private static System.Data.Linq.Mapping.MappingSource mappingSource = new Devart.Data.Linq.Mapping.AttributeMappingSource();
      public EntityContext ()
        : base("User Id=scott;Password=tiger;Server=ora", mappingSource) {
      }
    }
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

It works!

Postby freakshow » Wed 21 Jan 2009 13:26

It works! Excellent! Thank you!

Is the problem that the mappingsource from MS is beeing created/used if you do not specify this explicitly as Devart (just guessing)?

Will you/can you fix this in a future relase (so it is not necessary to create it manually)?
freakshow
 
Posts: 12
Joined: Mon 28 Jul 2008 12:38
Location: Oslo, Norway

Postby AndreyR » Wed 21 Jan 2009 14:28

It is already done. Next build will contain this fix.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16


Return to LinqConnect (LINQ to SQL support)