سؤال

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)?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى softwareengineering.stackexchange
scroll top