开发者

MySql connector with Entity Framework: Comparing Char(36) GUIDs in a LINQ Where clause

开发者 https://www.devze.com 2023-03-17 15:21 出处:网络
I think the title pretty much nails it. I am using a Char(36) in a MySql table which automatically gets recognized as a GUID when using the Entity Framework.

I think the title pretty much nails it.

I am using a Char(36) in a MySql table which automatically gets recognized as a GUID when using the Entity Framework.

Inserting the GUID is 开发者_StackOverflowno problem, but trying to compare it in a WHERE clause is a nightmare.

What I've tried:

First of all I've tried a WHERE element.GUID == GuidToCompare.

This resulted in LINQ to Entities does not recognize the method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' method, and this method cannot be translated into a store expression.

Then I tried to just convert the value to String, like so:

WHERE element.GUID.ToString() == GuidtoCompare.ToString()

This resulted in this error: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

So either way, I just can't compare them. I am ready to just not use GUIDs if they don't work out.


I know what was wrong: It was just a stupid error of myself.

The thing with comparing guids was quite correct, this was not the part that gave the error. Actually a later part in the same LINQ query fired the error. It compared ProviderUserKey (Object) to ID (int). The ProviderUserKey is essentialls an int, I just had to explicitly state it's type ( CType(Object, Integer) in VB.NET or (int)Object in C#)

0

精彩评论

暂无评论...
验证码 换一张
取 消