0

I have a web application (ASP.NET Core / C#) with 3 layers (web/presentation, business logic and data access).

I'm using Entity Framework to retrieve a record from an SQL Server database which is subsequently mapped to my model object. One of the retrieved columns contains an XML string where I need to extract some values from and map them to some properties of my Model object.

Of course the retrieval of the database-record is done in the data access layer; but would you place the parsing from the XML string in the data access layer too (since it's a matter of extracting data) or would you rather place it into the business logic layer (since the data access layer should only deal with the database)?

2

Definitely Data Access Layer.
The reason why, have nothing to do with how often structure of xml will change.

The fact that one of the columns contains data serialized as xml is implementation details of data access layer.
Business layer doesn't need to care about how data is saved to the database.

Your business layer should introduce an abstraction of retrieving method where method will return already serialized and ready to use data object.

MyData GetDataById(int id);

Then your Data Access Layer will implement it.

0

You ask:

but would you place the parsing from the XML string in the data access layer too (since it's a matter of extracting data) or would you rather place it into the business logic layer (since the data access layer should only deal with the database)?

Now ask yourself an other question:

Does the XML parsing contain any business logic that might change frequently or does it protect any invariants of your model?

  • If not: place it along the data access layer, since -in my read- this concern belongs to data manipulation/preparation layer.

  • If so: put it the business layer.

Worth remembering: always start simple and add complexity later when the need arises.

  • 1
    thank you for your feedback. in this case i'll put the xml-deserialization in the data access layer since it will definitely not change frequently (the structur of the xml has been the same for ages). – Dario Jul 11 '17 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.