I have two databases on two servers. My application mainly uses db1 on server1. However, there is one table that I will only read in db2 on server2.
Instead of creating a new DbContext for db2, we created a Linked Server and created a synonym for this table in db1. I have configured mappings for this in my first db1 code context. this works and I can get the data.
However, if I use any dates in my predicate, I get the following error:
A failure occurred while giving parameter information to OLE DB provider "SQLNCLI10" for linked server "server2".
My mapping is as follows:
ToTable("synonym");
Property(t => t.Id).HasColumnName("ID");
Property(t => t.Company).HasColumnName("Company");
Property(t => t.StartDate).HasColumnName("StartDate");
Property(t => t.EndDate).HasColumnName("EndDate");
Property(t => t.LastUpdatedDate).HasColumnName("LastUpdatedDate");
Property(t => t.LastUpdatedBy).HasColumnName("LastUpdatedBy");
I am trying to run the following query:
_context.Set<Synonym>()
.Any(s => s.Company == company
&& s.StartDate <= date
&& (s.EndDate >= date || s.EndDate == null));
If I delete the dates, the query runs fine.
server1 is SQL 2008
server2 is SQL 2005
, , - , , Entity Framework.