JonPSmith/EfCore.GenericServices

PerDtoConfig Support For Primitives?

Spinarooni opened this issue · 4 comments

Would it be possible for the PerDToConfig to support primitive value mappings to objects? What I have is a scenario where I pass an ID collection of ints to the client and then when they are sent back I need to map those IDs to an object collection.

Right now there is a type restriction on the PerDtoConfig class so I am not sure what kind of impact a change like this would have.

... primitive value mappings to objects. What I have is a scenario where I pass an ID collection of ints to the client and then when they are sent back I need to map those IDs to an object collection.

Firstly I'm not quite sure what you mean with "primitive value mappings to objects". Are the objects in an array, or in the database, or injected?

While you can do some very clever mappings in AutoMapper via the ForMember method (see GenericServices docs) its accessing the data that would be hard. I could describe some possible ways to do that, but its complicated and I have to ask - would it be easier to do by hand?

Have a look at my GenericServices Design Philosophy article where I suggest that really complex queries might be simpler to write by hand.

@JonPSmith The objects are in a Collection and the primitive values are in an array. For instance:

[1,2,3] would need to map to a collection of objects where the object is like class MyEntity { public int Id { get; set; } ...other props }

So reading from the database. That's possible but hard, because you don't have the DbContext in the PerDtoConfig class. You could use a SQL user defined function, which you can call without the DbContext, but that's about it (see example here).

Personally I would write my own service to do that, as its getting complex. GenericServices is for the simple/boring queries - anything complex I write by hand.

PS. If you can make the entities have a relationship with the main entity class it gets much easier.