[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Linq GUID mapping Problem

sree

8/18/2008 8:22:00 PM

Hi,

I have problem mapping uniqueidentifier column in DB with Entity in
Linq; I get the error :Unable to cast object of type 'System.Guid' to
type 'System.String'.


More info below:


I have a table with primary key as uniqueidentifier.

Ex table:
UID: uniqueidentifier (Primary Key)
LoginName: varchar
Email: varchar
Fax: varchar
Address: varchar


..Net code:
Generated the dbml file by dragging and dropping the table using
VS2008.


Code snippet:
MyDBDataContext db = new MyDBDataContext();
SecuredUser u = new SecuredUser();
u.UID = Guid.NewGuid();
u.LoginName = "testdbml";
u.EMail = "testdbml@sri.com";
u.Fax = "123-456-7890";
db.SecurityUsers.InsertOnSubmit(u);
db.SubmitChanges();
Console.ReadKey();


I am getting the runtime error "Unable to cast object of type
'System.Guid' to type 'System.String'." when the execution comes to
db.SubmitChanges();


Is there something that I am doing wrong?


Your help is appriciated.


Thanks in advance

Sri

1 Answer

Tim Jarvis

8/19/2008 10:39:00 PM

0

sree wrote:

> Code snippet:
> MyDBDataContext db = new MyDBDataContext();
> SecuredUser u = new SecuredUser();
> u.UID = Guid.NewGuid();
> u.LoginName = "testdbml";
> u.EMail = "testdbml@sri.com";
> u.Fax = "123-456-7890";
> db.SecurityUsers.InsertOnSubmit(u);
> db.SubmitChanges();
> Console.ReadKey();
>
>
> I am getting the runtime error "Unable to cast object of type
> 'System.Guid' to type 'System.String'." when the execution comes to
> db.SubmitChanges();

Sounds like the generated UID property is of type string, have you
tried Guid.NewGuid().ToString() instead?

Regards Tim.


--