I have a table, [User], that has an integer identity column, [ID]. I have created my entity model for my tables including User.
When trying to use the static User.CreateUser(ID, FirstName, LastName...) method, I have to supply the ID which is supposed to be generated by the db. Does anyone know how to make it so I don't have to supply the ID and let the db generate it?
Also, when trying to instantiate a new User, set it's properties, then call .SaveChanges(), I get an error about Identity Insert being OFF. Does anyone know how to solve this? Here's my exact error - "An error occurred while updating the entries. See
the InnerException for details.System.Data.SqlClient.SqlException: Cannot insert explicit value for identity column in table 'User' when IDENTITY_INSERT is set to OFF."
Thanks in advance for any help.
using (SpecialEdDollarwayEntities ctx = new SpecialEdDollarwayEntities())
{
SpecialEdEntityModel.User newUser = SpecialEdEntityModel.User.CreateUser(1, "chuck", "foster", "cfoster", "e@mail.com"); //CreateUser(id, FirstName, LastName, UserName, Email)
ctx.SaveChanges();
}
using (SpecialEdDollarwayEntities ctx2 = new SpecialEdDollarwayEntities())
{
SpecialEdEntityModel.User newUser = new SpecialEdEntityModel.User();
newUser.FirstName = "chuck";
newUser.LastName = "foster";
newUser.UserName = "cfoster";
newUser.Email = "e@mail.com";
ctx2.SaveChanges();
}
I won't be of much help, but of course you won't get much help... you're posting in a General ASP.NET Forum, specifically the ASP.NET 3.5 extensions
preview, about something not related to ASP.NET that is actually released (and definately not a preview) :)
The Entity Framework has its own forum, and its actually -very- active (you often get help from the developers themselves, its great):
I won't be of much help, but of course you won't get much help... you're posting in a General ASP.NET Forum, specifically the ASP.NET 3.5 extensions
preview, about something not related to ASP.NET that is actually released (and definately not a preview) :)
The Entity Framework has its own forum, and its actually -very- active (you often get help from the developers themselves, its great):
Thanks, but the reason I didn't post there was because it is still marked as Pre-Release. "ADO.NET Entity Framework and LINQ to Entities (Pre-release)"
They didn't change the title :) That said, you'll have to admit that its a bit closer than ASP.NET Future Preview (which is pre-pre-pre-pre-release, of a totally different product), hehehehehe. Not blaming you or anything. Was just trying to explain why no
one who could answer your question was looking (well, until our friend above did).
chuckdfoster
0 Points
7 Posts
Integer Identity Columns with Entity Framework
Aug 29, 2008 03:36 AM|LINK
I actually have 2 questions...
I have a table, [User], that has an integer identity column, [ID]. I have created my entity model for my tables including User.
Thanks in advance for any help.
using (SpecialEdDollarwayEntities ctx = new SpecialEdDollarwayEntities()) { SpecialEdEntityModel.User newUser = SpecialEdEntityModel.User.CreateUser(1, "chuck", "foster", "cfoster", "e@mail.com"); //CreateUser(id, FirstName, LastName, UserName, Email) ctx.SaveChanges(); } using (SpecialEdDollarwayEntities ctx2 = new SpecialEdDollarwayEntities()) { SpecialEdEntityModel.User newUser = new SpecialEdEntityModel.User(); newUser.FirstName = "chuck"; newUser.LastName = "foster"; newUser.UserName = "cfoster"; newUser.Email = "e@mail.com"; ctx2.SaveChanges(); }entity data framework
chuckdfoster
0 Points
7 Posts
Re: Integer Identity Columns with Entity Framework
Aug 31, 2008 08:35 PM|LINK
anyone?
chuckdfoster
0 Points
7 Posts
Re: Integer Identity Columns with Entity Framework
Sep 09, 2008 09:58 PM|LINK
Seriously? No one? Microsoft?
Herne
Member
10 Points
12 Posts
Re: Integer Identity Columns with Entity Framework
Sep 24, 2008 03:47 PM|LINK
I can hopefully help with 2.
I had the probably a little while ago, and this got me the solution - hope it does you too... :)
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3723071&SiteID=1
shados
Star
12285 Points
2229 Posts
Re: Integer Identity Columns with Entity Framework
Sep 24, 2008 03:56 PM|LINK
I won't be of much help, but of course you won't get much help... you're posting in a General ASP.NET Forum, specifically the ASP.NET 3.5 extensions preview, about something not related to ASP.NET that is actually released (and definately not a preview) :)
The Entity Framework has its own forum, and its actually -very- active (you often get help from the developers themselves, its great):
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=533&SiteID=1
chuckdfoster
0 Points
7 Posts
Re: Integer Identity Columns with Entity Framework
Sep 24, 2008 04:50 PM|LINK
thanks! that helps alot!
chuckdfoster
0 Points
7 Posts
Re: Integer Identity Columns with Entity Framework
Sep 24, 2008 04:52 PM|LINK
Thanks, but the reason I didn't post there was because it is still marked as Pre-Release. "ADO.NET Entity Framework and LINQ to Entities (Pre-release)"
shados
Star
12285 Points
2229 Posts
Re: Integer Identity Columns with Entity Framework
Sep 24, 2008 05:03 PM|LINK
Herne
Member
10 Points
12 Posts
Re: Integer Identity Columns with Entity Framework
Sep 25, 2008 08:27 AM|LINK
No worries, glad you managed to decipher my message. I of course meant "problem" instead of "probably".... d'oh :)
As shados said, it's a good forum and you usually get responses fairly fast.