Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 22, 2012 08:08 AM by Decker Dong - MSFT
Member
1 Points
33 Posts
Dec 21, 2012 06:15 PM|LINK
Hi, in the designer view I've set the StoreGeneratedPattern property of my userID field to Identity as I believe this makes it an auto number?
Yet the EF code that was generated requires me to provide a value:
public static tblUser CreatetblUser(global::System.Int32 userID, global::System.String email)
{tblUser tblUser = new tblUser();
tblUser.UserID = userID;
tblUser.Email = email;
return tblUser; }
What am I doing wrong?
Contributor
2777 Points
1161 Posts
Dec 21, 2012 09:33 PM|LINK
Your need these on your key field if you want it to autogenerate:
[Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] decimal id {get; set;} ...
All-Star
118619 Points
18779 Posts
Dec 22, 2012 08:08 AM|LINK
PuzzledGeek in the designer view I've set the StoreGeneratedPattern property of my userID field to Identity as I believe this makes it an auto number?
Yes, but please make sure that your real db's column's DefaultValue should be also set to newid().
What's more, if you are using EF(Code-first), you cann take 2nd man's advice.
Reguards!
PuzzledGeek
Member
1 Points
33 Posts
StoreGeneratedPattern = Identity but still get asked to provide a value
Dec 21, 2012 06:15 PM|LINK
Hi, in the designer view I've set the StoreGeneratedPattern property of my userID field to Identity as I believe this makes it an auto number?
Yet the EF code that was generated requires me to provide a value:
public static tblUser CreatetblUser(global::System.Int32 userID, global::System.String email)
{tblUser tblUser = new tblUser();
tblUser.UserID = userID;
tblUser.Email = email;
return tblUser; }
What am I doing wrong?
eric2820
Contributor
2777 Points
1161 Posts
Re: StoreGeneratedPattern = Identity but still get asked to provide a value
Dec 21, 2012 09:33 PM|LINK
Your need these on your key field if you want it to autogenerate:
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
decimal id {get; set;}
...
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: StoreGeneratedPattern = Identity but still get asked to provide a value
Dec 22, 2012 08:08 AM|LINK
Yes, but please make sure that your real db's column's DefaultValue should be also set to newid().
What's more, if you are using EF(Code-first), you cann take 2nd man's advice.
Reguards!