Reputation: 19
I have a table of Owner:
CREATE TABLE [dbo].[Owner] (
[OwnerID] INT IDENTITY (1, 1) NOT NULL,
[Name] NVARCHAR (50) NOT NULL,
[Username] NVARCHAR (50) NOT NULL,
[Password] NVARCHAR (50) NOT NULL,
[Phone] NVARCHAR (50) NOT NULL,
[Mail] NVARCHAR (50) NOT NULL,
[Description] NVARCHAR (50) NOT NULL,
[Image] IMAGE NULL,
PRIMARY KEY CLUSTERED ([OwnerID] ASC)
);
And I want the key field "OwnerID" to auto increment (starting from 1), but it doesn't work.
The c# code is:
Owner owner = new Owner();
owner.Username = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName")).Text;
owner.Name = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Name")).Text;
owner.Password = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Password")).Text;
owner.Phone = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Phone")).Text;
owner.Mail = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Email")).Text;
owner.Description = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Description")).Text;
When I debug I can see that the field OwnerID is set to 0 (I don't know why) and at the end I have an error message:
The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.
Upvotes: 0
Views: 76
Reputation: 10374
If your using EF then you should create a Configuration for Owner
:
class OwnerConfiguration: EntityTypeConfiguration<Owner>
{
public OwnerConfiguration()
{
HasKey(x => x.OwnerId);
}
}
Upvotes: 1