Can I use AutoMapper with CSLA ? #2114
Replies: 2 comments 1 reply
-
I moved this to Discussions, as it isn't really a work item for the backlog. I think you can use AutoMapper. You can absolutely use the DataMapper built into CSLA. In either case, keep in mind that these work on public properties, so can't set non-public values. Also, setting a property will trigger business rules (authorization, validation, etc.) unless wrapped in a BypassPropertyChecks block. |
Beta Was this translation helpful? Give feedback.
-
I'm using Automapper without issue. The only thing I see in my mapping configuration that looks particular to CSLA is:
I use it like this:
If the entity returns the child object as well I do something like this:
Otherwise I'll pass whatever parameter is necessary in the child fetch to load itself. I haven't come across an instance yet, where I had to mark a child as dirty as @kcabral817 mentioned. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In the past I have used AutoMapper to automatically map properties from one class to another.
I was wondering whether it would be possible to use AutoMapper with CSLA or whether CSLA has its own built-in data mapper ?
My scenario is:
I have a Blazor WebAssembly project which I created using the CSLA Blazor Sample from this repo.
I have a Razor Component with the following code:
This then calls the method attributed with the
[Fetch]
attribute from theSharedModelProductsCompareViewList
class.The data is then populated into the
DataAccessCompareProductsViewResult
class by calling theCompareSelectedProducts
method on the DAL. TheDataAccessCompareProductsViewResult
class which sits in the DataAccess project, class looks like this:When it comes to populating the
Header
andRows
properties on theSharedModelProductsCompareViewList
class I have to transfer the data from theDataAccessCompareProductsViewResult
class which sits in the DataAccess project into theSharedModelCompareProductsViewResult
class in the Shared project as the Blazor WebAssembly project only has a reference to the Shared project.The
SharedModelCompareProductsViewResult
class in the Shared project looks like this:I have had to write some clunky extension methods to take the data from the DataAccess class into the Shared class and these methods look like this:
Is there an easy way to do this without doing this hacky extension methods, something like AutoMapper ?
Beta Was this translation helpful? Give feedback.
All reactions