Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to know the flow of NHibernate pure c#.
What is the difference of castle active record and NHibernate pure?
Kindly teach me if there is someone who know well about them.
I assume pure means without Castle or Fluent.
There is much to explain which cannot be covered in this answer so I will just note the steps.
Create Entity (POCO) classes based on your database structure.
Create mapping (.hbm.xml) files based on your Entity classes and database structure. To avoid mapping files, you can choose Fluent way which is other topic for discussion.
Decide the location for configuration (web.config/app.config/code) and do the necessary configurations.
Write CRUD methods in your DAL using various (Linq/Query/Criteria/QueryOver/HQL) ways available.
Call BuildSessionFactory at startup of application.
Call DAL methods.
NHibernate documentation is good source of information.
This article1 and article2 should be good starting point for you.
For Castle, I suggest you ask separate question.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm building a C# WPF app that will use IBM iSeries data for starters but will use oracle data via web service later. In order to switch between them (and support testing) we create interfaces and program the view to interface, right? Each of the data sources would be responsible for mapping to a common DTO structure used in the view model.
So if these two data sources that implement the interfaces are in separate projects, where are the interfaces defined? I'm thinking about how to define the interfaces so I don't have to keep up separate versions in the respective data source projects. If I create the interfaces in the view then it would create circular reference, the data source needing the view for the interfaces and the view needing the data source for dependency injection.
Please forgive me for the rather generic question. I'm not asking "how do I structure my app", it's more of how do I solve the specific issue of the mechanics of the interfaces.
Thanks, Mike
Put them in a separate project. Add a reference to that project wherever you want to use them.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
We have to microservices.
How can we use an entity model from one microservice to another microservice without needing to maintain codes on both end?
The goal is to take the jsonData from a microservice and map it to entity model that exist in another microservice.
What is the best practice here?
You will need the assembly that contains the types you want to serialize/deserialize jsons. I think it is ok because when you have one service, you expect it to run autonomously, so, if you provide additional fields it should work (because it will not be affected by the deserialization). Now missing fields, the service will thrown exceptions and it is expected as part of the business.
One option, but not recommended (in my opinion), is to deserialize your json into dynamic and you will be able to navigate on the result as you want. I am not sure about the performance of this.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I work on school enterprise project and I need create data layer with design patterns. Can you give me some hint where to start and how patters could I use ? Thanks
Edit:
I have not use frameworks for ORM.
You could try the repository pattern and unit of work pattern
One of the common pattern for the data layer is the Data Access Objects. Anyway you can also use ready-to-use libraries such as the Microsoft Solution Entity Framework or NHibernate.
Also you can read this link with a lot of suggestions
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In C# commonly use DTO classes for data transfer. But also we can transfer data using Entity Framework generated class. But most of the time we uses DTOs to transfer data. Why DTOs needs to pass data across layers instead of using Entity Framework generated classes.
I think one reason, using dto classes does not directly bind the client to your database model, as it would if you were transferring ef classes. It allows you to make changes to your backend and in some cases keep these changes from effecting your clients. There are truly many more reasons, I think doing some research on the net will help more perhaps, there are many fantastic articles. However you will have to decide whether the use of dto classes fit into your current project. Some people say dto classes are bad and they go in depth to explain why they say so, others say the opposite and again explain why they say so. You will need to determine which is best for the task at hand. Overall I think answers for this question would be opinion dependant. Personally, I love dto classes.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Let's say I have a class named Rectangle and it has some attributes like: color, width, height etc. So this class will for sure describe this object but I also want to save this object to database and later read and create object from db.
My question is should this class also have methods like "SaveRectangle", "GetOneRectangle ", "GetAllRectangles", "EditRectangle" that handles the SQL operations or is there a other good practice?
I would suggest you check out Martin Fowler's "Patterns of Enterprise Architecture".
There are several different patterns for data persistence. The pattern you describe is "Active Record". It can definitely make things easier in the short term but I have found that it often leads to issues when working with many objects.
I typically choose to use a combination of the "Data Mapper" and "Table Data Gateway" patterns that separates storage/retrieval concerns from the objects themselves. That allows me to handle both separately and, possibly, more efficiently.