-
-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
I use DelegateDecompiler together with EF core.
I map entities to models. I have model base classes and subclasses (simple example below).
Each model contains a mapping method that will be used to project the entity on the model (I don't use AutoMapper).
Those mapping methods are decorated with the [Decompile] attribute.
In the subclass mapping method, I want to use the base class mapping method.
The setup below compiles but gives a runtime error: expression must be writeable (Parameter 'left').
Is this way of working (nested [Decompile] methods) possible with the library 0.34.2?
public class EquipmentBaseModel
{
public int EquipmentId { get; set; }
public string? Name { get; set; }
public short? EquipmentTypeId { get; set; }
public string? Imonumber { get; set; }
// MAPPINGS
[Decompile]
public static EquipmentBaseModel FromEntity(EquipmentEntity entity)
{
EquipmentBaseModel model = new EquipmentBaseModel();
model.EquipmentId = entity.EquipmentId;
model.Name = entity.Name;
model.Imonumber = entity.Imonumber;
model.EquipmentTypeId = entity.EquipmentTypeId;
return model;
}
}
public class EquipmentTestModel : EquipmentBaseModel
{
public bool? Operational { get; set; }
public string? ConstructionYear { get; set; }
// MAPPINGS
[Decompile]
public new static EquipmentTestModel FromEntity(EquipmentEntity entity)
{
EquipmentTestModel model = (EquipmentTestModel)EquipmentBaseModel.FromEntity(entity);
model.Operational = entity.Operational;
model.ConstructionYear = entity.ConstructionYear;
return model;
}
}
public async Task<Result<IReadOnlyList<EquipmentModel>>> GetEquipmentAsync()
{
List<EquipmentTestModel> data = await dbContext.Equipment.AsNoTracking()
.Include(x => x.EquipmentType)
.Select(x => EquipmentTestModel.FromEntity(x))
.ToListAsync();
}
Metadata
Metadata
Assignees
Labels
No labels