[Solved] Entity Framework Error: Cannot resolve the collation conflict between in the equal to operation

AliYilmaz
 
on Apr 27, 2022 10:32 AM
707 Views

Hi,

I am getting this error in Entity Framework inner join. How can I resolve this error. without touching the database.

Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CS_AS" and "Turkish_CI_AS" in the equal to operation.

 I need to add below code.

var result = from cartItem in contex.CartItem
join article in contex.Article 
on cartItem.Articel_Oid equals article.Articel_Oid
join saleSeason in contex.B2B_SaleSeasonDefinition
 
on new { SaleSeasonOid = cartItem.SaleSeason_Oid, SaleSeasonId = cartItem.SaleSeason_Id }
equals new { SaleSeasonOid = saleSeason.Oid, SaleSeasonId = saleSeason.Id }
 
join customer in contex.CurrentCustomer
on cartItem.Customer_Code equals customer.Code
 
 
where cartItem.Customer_Code == Customer
group cartItem by new { article.Articel_Oid, article.Articel_Code, article.Model_ArticelName, cartItem.SaleSeason_Oid, cartItem.SaleSeason_Id, cartItem.UnitPrice, customer.ShippingCost, customer.FreightVAT, cartItem.SubUnitPrice }
 
into cart
select new ArticleInCart
{
    Articel_Oid = cart.Key.Articel_Oid,
    Article_Code = cart.Key.Articel_Code,
    Articel_Name = cart.Key.Model_ArticelName,
    SumQuantity = cart.Sum(x => x.Quantity),
    UnitPrice = cart.Key.UnitPrice,//cart.Sum(x => x.Price) / cart.Sum(x => x.Quantity),
    Price = cart.Sum(x => x.SubTotal),
    SaleSeason = cart.Key.SaleSeason_Oid,
    SaleSeason_Id = cart.Key.SaleSeason_Id,
    Kargo = cart.Key.ShippingCost,
    KargoVergi = cart.Key.FreightVAT,
    SubUnitPrice = cart.Key.SubUnitPrice,
};
 
return result.OrderBy(x => x.Article_Code).ToList();

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Apr 27, 2022 11:36 AM

When this gets to the database, you end up trying to compare two varchars that are stored using different collations. One is using the SQL collation for Latin1 General Case Insensitive Accent Sensitive, and the other is the Windows flavour of that collation.

In SQL you could resolve this by using collate against the relevant columns to make sure they were compared in the same collation. In your entity framework, you will have to find some other way to make the collations the same.

Reference:

https://stackoverflow.com/questions/14989127/tolist-gives-error-cannot-resolve-collation-conflict

https://social.msdn.microsoft.com/Forums/en-US/915194c9-910e-4c8b-94d7-9085494aed60/cannot-resolve-the-collation-conflict-between-8220cyrillicgeneralcias8221-and?forum=aspsqlserver