Trouble making LINQ-to-SQL work with Oracle.DataAccess, using C#
785293Jul 15 2010 — edited Aug 23 2010I have an existing application using Microsoft's ADO.NET adapter for Oracle, System.Data.OracleClient. For various reasons I wish to see if it can be ported to use Oracle.DataAccess.Client instead. I then run into this problem: When the LINQ query is activated, I get an exception, ORA-00923, "FROM keyword not found where expected". Note, that this is code that works using System.Data.OracleClient. I have only changed the "using" statement, the reference, and the provider used for the connection.
Here are some details (they are somewhat reduced to blot out company-confidential info). My LINQ-to-SQL class, hand-coded:
[Table(Name = "SAMPLE")]
public class Sample
{
[Column(Name = "ID", IsPrimaryKey = true, CanBeNull = false)]
public string Id { get; set; }
[Column(Name = "DATE_OF_SAMPLE", IsPrimaryKey = true, CanBeNull = false)]
public DateTime DateOfSample { get; set; }
[Column(Name = "FILE_ID")]
public decimal? FileId { get; set; }
[Column(Name = "COLLECT_TIME")]
public DateTime? CollectTime { get; set; }
}
the usual private datacontext:
public class MyDataContext : DataContext
{
public Table<Sample> Samples;
public MyDataContext(OracleConnection conn) : base(conn) { }
}
OracleConnectioon conn = GetDatabaseConnection(connHandle); // taking connection sting and provider from Configuration data
MyDataContext dc = new MyDataContext(conn);
Table<Sample> samples = dc.GetTable<Sample>();
var q = from s in samples
where s.Id.Equals(xName) &&
s.DateOfSample.Equals(today)
select s;
if (!(q.Any<Sample>())) <---- here I get the ORA-00923 exception
{
}
The debugger shows the SQL expression, I cannot see anything wrong with it, except maybe that it uses '@' instead of ':'. But I don't believe that the problem is that trivial.
q
{SELECT [t0].[ID] AS [Id], [t0].[DATE_OF_SAMPLE] AS [DateOfSample], [t0].[FILE_ID] AS [FileId], [t0].[COLLECT_TIME] AS [CollectTime]
FROM [SAMPLE] AS [t0]
WHERE ([t0].[PLMNID] = @p0) AND ([t0].[DATE_OF_SAMPLE] = @p1)}
I am using Visual Studio 2008, with Oracle.DataAccess version 2.112.1.0. My Oracle server is, I believe, version 8.