Page 1 of 1

Querying a GUID field using Linq

Posted: Sat 09 Oct 2010 10:45
by DeepSeaDave
Posted: Sat 09 Oct 2010 10:42 Post subject: Guids and Linq

--------------------------------------------------------------------------------

I have a database I designed that contains a primary key I designed as System.Guid. The Server Data Type is defined as CHAR(36). I am able to use linq to add records.

The following query works if I'm trying to retrieve all donors:
Donors = From Info In DataContext.Donors Select Info
For Each Donor In Donors
'do stuff
Next

When I try to retrieve a single record:
Donor = (From Info In DataContext.Donor Where Info.ID = SomeGuid Select Info).FirstOrDefault

I get a runtime error that says "Cannot use "CHAR(255)" type value in "Guid" type argument". I had also tried defining the ID column as BINARY(16) and would get a similar error.

How can I use Linq to query a single record and use the Guid field?

Posted: Mon 11 Oct 2010 09:25
by StanislavK
I've sent you a test project in a letter, please check that it was not blocked by your mail filter. Please specify what should be changed in the project to reproduce the problem or send us your sample.

The table used in the sample is defined as

Code: Select all

CREATE TABLE guid_id(
  id CHAR(36),
  val VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (id)
)
ENGINE = MYISAM
Also, please specify the versions of dotConnect for MySQL and MySQL server you are using.