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