So I would like to set default value for EventId where EventID id uniqueidentifier and primary.
I don't won't to set id value from code but autogenerate it from database.
After runing it EventID is equql to Guid.Empty {000-00000-00000000000}
CREATE TABLE [dbo].[Events](
[EventID] [uniqueidentifier] NOT NULL,
[Title] [nvarchar](50) NOT NULL,
[Description] [nvarchar](2500) NOT NULL
)
ALTER TABLE [dbo].[Events] ADD DEFAULT (newid()) FOR [EventID]
GO
Goraleye
Member
295 Points
370 Posts
autogenerate ID from database where id is Guid
Dec 16, 2012 01:07 PM|LINK
Hi,
I m using SQL server and Entity Framwork
So I would like to set default value for EventId where EventID id uniqueidentifier and primary.
I don't won't to set id value from code but autogenerate it from database.
After runing it EventID is equql to Guid.Empty {000-00000-00000000000}
How can I set value ? (int identity woks fine )
oned_gk
All-Star
31305 Points
6398 Posts
Re: autogenerate ID from database where id is Guid
Dec 16, 2012 01:14 PM|LINK
RameshRajend...
Star
7983 Points
2099 Posts
Re: autogenerate ID from database where id is Guid
Dec 16, 2012 01:35 PM|LINK
http://www.mssqltips.com/sqlservertip/1600/auto-generated-sql-server-keys-with-the-uniqueidentifier-or-identity/
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: autogenerate ID from database where id is Guid
Dec 17, 2012 01:24 AM|LINK
Hi,
If your way doesn't work properly, you can try:
1) Since your ef's classes (I mean generated) must be "partial class", so you can just write another class with the same name.
2) Then re-write the OnInitialized, please initialize the entity model instance with something like:
GuidProperty = Guid.NewGuid();