2

I am using the Entity Framework with MySQL, and every table has a ID column that is of type CHAR(36). In the EDMX file they are all of type System.Guid, and the SSDL xml looks like:

<EntityType Name="Accounts">
  <Key>
    <PropertyRef Name="ID" />
  </Key>
  <Property Name="ID" Type="guid" Nullable="false" />
  ...

When I try to use any method (Single, Where, Any, etc), it throws an InvalidOperationException stating that the sequence contains no elements. Here's the weird part, if I expand the results view in the debugger, it does show the elements. The GUID values are the same, so it should be returning exactly one element. I have included a picture below (right click save as to see larger), but can anyone explain what is going on here? The GUID's do match:

(method argument) accountID: 
{7767402f-9b29-4026-b40d-6eb991748f8c}
(should match) element in results view:
{7767402f-9b29-4026-b40d-6eb991748f8c}

enter image description here

David Anderson
  • 13,558
  • 5
  • 50
  • 76
  • Try switching to `SingleOrDefault()` and checking `account` for `null`. If you get to the next line and account is null then the GUIDs don't match. – Bala R Aug 17 '11 at 22:15
  • That isn't related to this problem. It is of course going to return null, because the predicate fails. The problem is that it should not, because the ObjectSet does contain two results that has exactly one account with the matching ID. The question at hand is why the predicate is failing for this. This application is built to support both MSSQL and MySQL, and when configured to MSSQL the code works properly. It is MySql specific, but I don't know why it is failing. If you look at the picture you will see the matching result set. – David Anderson Aug 17 '11 at 22:18

1 Answers1

0

My bet is that it's a bug in the MySQL connector and that it has to do with how the GUID is stored in the DB. For some reason the comparison is not working. I think you should use BINARY(16) instead of CHAR(36).

Check out the answer to this question: Storing MySQL GUID/UUIDs

Community
  • 1
  • 1
alf
  • 18,372
  • 10
  • 61
  • 92