Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Supporting Key names other than "Id" #285

@zachrybaker

Description

@zachrybaker

First off, this is a very convenient library, especially combined with the EFC Generator, especially when your database design is "ideal."

@pwelter34 I'm curious if you have considered making it work for tables whose PK is not named "Id." Let's ignore compound keys for a moment. While Id is the EF convention, it is not an EF requirement. Wouldn't it be nice if it wasn't a requirement here?

From what I can tell, the only place that we run into trouble is in the EntityDataContextHandlerBase's Read method. The Where clause has a linq expression which is server-evaluated looking for an "Id" field. While I could add a view or a computed column to get around this hard-coded property name, folks probably prefer to keep their db as pure as possible.

One thought is that if all these EFC-facing handlers and even EntityDataContextHandlerBase were themselves implementations of generic interfaces, perhaps we could substitute other implementations to get us the desired key name in Read implentation. Just a thought.

Otherwise, the "Id" name is not an issue without code workarounds. The create/delete/update handlers don't suffer this above issue on the EF side. On the model-facing side, this is a viable workaround at the entity level to avoid issues:

    [NotMapped]
    public string Id { get => MyActualKey; set => MyActualKey= value; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions