-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Open
Description
My Id is defined in tSQL as
id NVARCHAR (128) DEFAULT (NEWID()) NOT NULL
and in C# as
public Guid Id { get; set; }
Dapper generates an error Invalid cast from 'System.String' to 'System.Guid'
. One solution (from here) is to add a private IdString thus
private string IdString { get; set; }
public Guid Id
{
get
{
return new Guid(IdString);
}
set
{
IdString = value.ToString();
}
}
and changing the tSQL from id
to Id AS IdString
.
It's a bit painful not to be able to use SELECT *
because of that alias.
Using Guid
as an id column seems common practice.
Should there not be a built in mechanism for casting between Guids and strings?
previousserver