Marcel
Marcel

Reputation: 1074

Binary(16) as primary key: Lightswitch recognizes GUID but can't write them correctly

We must use GUIDs, identifying records for an export from SQL Server to MySQL. We've got a table in MySQL like this:

CREATE TABLE IF NOT EXISTS `images` (
  `idImage` binary(16) NOT NULL,
  `caption` varchar(1000),
  `preview` blob,
  `lastModified` datetime NOT NULL,
  PRIMARY KEY (`idImage`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

And insert data by this:

INSERT INTO `images` 
VALUES (
  -- .NET: Guid.Parse("12345678-1234-1234-1234-123456789001")
  UNHEX(REPLACE('78563412-3412-3412-1234-123456789001','-','')),
  'My first sample image',
  NULL,
  '2014-08-26 15:51:25'
);

After I setup the datasource in Lightswitch I got this: Lightswitch recognizes Binary(16) as Guid Lightswitch recognizes my GUID primary key!!! Simply Awesome :-) Here's the screen: Guid on a screen Yeah! That's great!

But now, I'd like to CRUD:

What did go wrong here?

Upvotes: 0

Views: 306

Answers (1)

R.Kellner
R.Kellner

Reputation: 56

This problem is easy to solve. You have to tell the MySQL-Connector to use another (older) illustration of GUIDs. Normally this is done by adding

Old Guids=true;

to the connection string. In your case (Lightswitch project) you have to change this option with the "Data Source Wizard". You'll find this in the menu:

Attach Data Source Wizard > Connection Properties >Advanced Properties

enter image description here

That's it!

Upvotes: 1

Related Questions