AutoHistory icon indicating copy to clipboard operation
AutoHistory copied to clipboard

Problem with combined pk

Open fuzolan opened this issue 6 years ago • 5 comments

If you use a combined pk then there is an issue that you can not delete those rows. you can create it and they will be no record in history table. But a remove returns in an error. Tested with mssql.

fuzolan avatar Nov 19 '18 13:11 fuzolan

Please provide the detail exception info

rigofunc avatar Dec 03 '18 07:12 rigofunc

I was having the exact same issue.

To reproduce, create an entity with a composite primary key of 2 strings properties:

class MyObject() { public string StringA { get; set; } public string StringB { get; set; } }

Define the primarykey with : modelBuilder.Entity<MyObject>() .HasKey(t => new { t.StringA, t.StringB });

Autohistory is working fine when adding (as the RowId is empty), but raising an exception on delete (and I suppose any other modifications). The exception I get is : "Data too long for column 'RowId' at row 1"

This is because the default RowIdMaxLength is setup to 50 (smaller than the expected key).

@fuzolan the solution is to raise the RowIdMaxLength in AutoHistoryOptions to match your app need.

Edit: I would say that @xyting you could add a note on the wiki about composite primary key and close this issue.

matthieume avatar Dec 06 '19 10:12 matthieume

Yes, have some issues about composite primary key, but I think maybe have any solution can solve this issues

rigofunc avatar Dec 13 '19 07:12 rigofunc

Does Autohistory not currently support composite keys? I cannot get any tables with them to push history. If you have a fix, is this going to be put in place soon, or should I adjust my tables instead?

ghost avatar Feb 20 '20 17:02 ghost

i also have this issue, for about 8 months now. and oddly, after i refactored these tables to have single column primary keys they are still being excluded from the autohistory. And it is passing through the same .EnsureAutoHistory() fxn as the rest. Any tips @xyting ?

j5aenz avatar Aug 18 '20 16:08 j5aenz