Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Invalid primary key detection in ConventionModelMapper #156

Closed
satano opened this issue Oct 22, 2018 · 0 comments
Closed

Invalid primary key detection in ConventionModelMapper #156

satano opened this issue Oct 22, 2018 · 0 comments
Assignees
Labels

Comments

@satano
Copy link
Member

satano commented Oct 22, 2018

Library name and version

  • Kros.KORM 3.7.2

Description

We try to find primary key of the table In ConventionModelMapper.OnMapPrimaryKey() method. It looks for Key attribute and also uses a name convention. The problem is, it uses both ways at the same time, so it can wrongly find a primary key composed of two columns. One column with the attribute and the other with conventional name. It makes troubles later - for example BulkUpdate fails with the message, that primary key of the table is composite.

Steps To Reproduce

  1. Make a model class
public class Data
{
    [Key]
    public int RowId { get; set; }
    public int Id { get; set; }
    public string Data { get; set; }
}
  1. Make an DbSet of this type, and add some data to it.
  2. Call DbSet.BulkUpdate().
  3. It fails with the message, that there is no primary key or it is composite. In this case, it is composite, composed of RowId column found by attribute and Id column found by convention.

Expected behavior

ConventionModelMapper should find correct primary key. The Key attribute has precedence over conventional name. So convention with Id column name should be used only if there is no column with Key attribute - in case of example, the RowId column is primary key. Consequently BulkUpdate (and other operations we do not know about yet) should work.

Notes

Maybe we should also add check that there can be only one Key attribute. We do not support composite primary keys in operations and this attribute is to ready for it either. If we want to support composite primary key to be declared with the attribute, it should have a argument which specifies the order of columns in primary key. Or maybe implement the order.

@satano satano added this to the Kros.KORM v3.8.0 milestone Oct 22, 2018
@satano satano added the bug Something isn't working label Oct 22, 2018
@satano satano self-assigned this Oct 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant