axelheer / nein-linq

NeinLinq provides helpful extensions for using LINQ providers such as Entity Framework that support only a minor subset of .NET functions, reusing functions, rewriting queries, even making them null-safe, and building dynamic queries using translatable predicates and selectors.
MIT License
521 stars 22 forks source link

[Question/Feature Request] Overwrite member/property mapping #37

Closed SpaceOgre closed 10 months ago

SpaceOgre commented 2 years ago

Hi, I'm having some problems with reusing expressions and stumbled upon this really nice library!

Now I wonder if the following is already possible with NeinLinq and if not if it would be possible to implement (I guess it might be tricky).

I have a DTO class that is display in a list, some of the properties in the DTO should be featched from diffrent places depending on selections of the users so I have done this now:

public class DTO
{
    public Guid Id {get;set;}
    public string Name {get;set;}
    public string ExtendedName {get;set;}
}

Expression<Func<Education, StaticEducation, DTO>> base = (e, _) => new DTO { Id = e.Id, Name = e.Name};
Expression<Func<Education, StaticEducation, DTO>> extended = (e, es) => new DTO { ExtendedName = es.Name};

var combined = base.Apply(extended);

This works but I would like to do this: Override the first Name mapping with the second one like this:

public class DTO
{
    public Guid Id {get;set;}
    public string Name {get;set;} 
}

Expression<Func<Education, StaticEducation, DTO>> base = (e, _) => new DTO { Id = e.Id, Name = e.Name};
Expression<Func<Education, StaticEducation, DTO>> extended = (e, es) => new DTO { Name = es.Name};

//Here Id is from Education and Name is from StaticEducation
var combined = base.Apply(extended);

So my two questions:

  1. Is this possible with NeinLinq today somehow? (I have looked long at the documentation and code but could not figure it out)
  2. If not would it be hard to implement as a feature?
axelheer commented 2 years ago

This isn't possible at the moment, but shouldn't be that hard to implement.

I can look into that.