Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Mon, 18 Aug 2008 13:21:56 -0700 (PDT),    group: microsoft.public.dotnet.framework        back       


Linq GUID mapping Problem   
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
date: Mon, 18 Aug 2008 13:21:56 -0700 (PDT)   author:   sree

Re: Linq GUID mapping Problem   
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.


--
date: Tue, 19 Aug 2008 15:38:41 -0700   author:   Tim Jarvis

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us