Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Method 'Boolean Equals(System.String, System.StringComparison)' has no supported translation to SQL.

$
0
0

Hi peeps,

I have a table that is defined as follows:

Id(pk)        int
CountyName nvarchar(100)

Before I insert a new CountyName into the table, I would like to ensure that its a unique record by using the following code:

 public static Func<DataClassesDataContext, string, bool> isPresent =
        CompiledQuery.Compile((DataClassesDataContext db, string newCounty) =>
        db.Counties.Any(p => p.CountyName == newCounty));

the code fails with the following error:

Method 'Boolean Equals(System.String, System.StringComparison)' has no supported translation to SQL.

I have modified the code to:

public static Func<DataClassesDataContext, string, bool> isPresent =
        CompiledQuery.Compile((DataClassesDataContext db, string newCounty) =>
        db.Counties.Where(p => p.CountyName == newCounty).Count() > 0);

The operation fails with the same error.

I have read elsewhere that the problem could be in the database collation, but upon checking the table design in SSMS the table collation for the CountyName column is defined as <database default>.

I am using the Web Application project type and it compiles without errors. I created aWebsite project and tested the same code and it works. But for theweb application project type it doesn't.

Update

I can insert records to the table from SSMS and view them on a gridview in the website frontent. Deleting those records from the frontend works fine too. But checking whether a record already exists before i insert a new one simply doesn't work.

Maybe I missed something. I highly appreciate any input on how to make this work. Thanks.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>