DapperLib / DapperLib/DapperAOT

Mapping inherited class properties

Open
#93 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug enhancement
Dominant language
C#
Stars
472
Forks
43
Avg merge
1d 4h
Merged PRs (30d)
18

Description

Right now when using a base class for your entities like this

public abstract class EntityBase
{
    public long Id { get; set; }
}

public class Entity1 : EntityBase
{
    public string Name { get; set; }
}

Then the Id property will not be read by the code generated.

It only works when putting the Id directly into Entity1 (otherwise it never gets mapped, always default 0 for any query). I think it´s fairly common to want to enforce consistent naming of ids and timestamps. Although, this can be enforced with interfaces too I suppose (doing that now instead).

The above should either work, or a the analyzer should give you a warning about this (in case this is not gonna be implemented anytime soon). I don´t yet know enough about compile time generators to know how hard it is to figure out that there is a base class and walk back up the class tree.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides a reproducible EntityBase and Entity1 example but names no files or tests. Start by reproducing the generated mapping with the inherited Id property, then trace the relevant generated-code path; done means inherited properties are mapped correctly or the analyzer reports that they are unsupported.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.