i have composite primary keys today which is not supported by ORMLite.
I have added a new identity column as part of the primary key to solve this Unique Constraint issue.
But the problem is that when i try to insert a new item i get this errormessage
An explicit value for the identity column in table ‘dbo.RegisteredUsers’ can only be specified when a column list is used and IDENTITY_INSERT is ON.
This happens even if the identity column is null (IdentityId). Also tried to add [AutoIncrement] but without any success
[ServiceStack.DataAnnotations.AutoIncrement]
public int IdentityId { get; set; }
The other columns as are part of the primary key (ApplicationId and CustomerId is set as guid and are filled with data).
I have tried now for 2 days to get around this problem with any success so please guide me.
Hi mythz,
but the thing is that i dont want to use Identity_insert.
This is only used when you want to put your own value in the identity column. I want it to be auto incremented.
Thats why i set null as my value on the identity column.
Please provide an isolated stand-alone example of the OrmLite query that reproduces the issue, not an entire Application where the query is hiding behind an API. It shouldn’t need to be anything more than the table class definition and the client code that throws the Exception.
When creating the example please run it with:
LogManager.LogFactory = new ConsoleLogFactory(debugEnabled:true);
Hi,
i have now added a console application inside the project whice do the save and generates the error.
Im not sure how to use the LogManager but added that line aswell in the console app.
If the Issue is the [AutoIncrement] column not being populated, that can only be applied to the primary key which is the Id property not the IdentityId property.
So you need to use the [PrimaryKey] property to make it the Primary Key:
public partial class Customer
{
[Alias("RegisteredUserId")]
public Guid Id
{
get; set;
}
[AutoIncrement]
[PrimaryKey]
[Alias("Id")]
public int IdentityId { get; set; }
}
The [AutoIncrement] property on a non-primary key is not supported.
I will try that.
I can see it’s trying to join identity column with registereduserid column.
FROM "RegisteredUsers" LEFT JOIN "CompanyRegisteredUsers" ON("RegisteredUsers"."IdentityId" = "CompanyRegisteredUsers"."RegisteredUserId")WHERE "RegisteredUsers"."ApplicationId" = @0 AND ("CompanyRegisteredUsers"."ApplicationId" = @1)