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.
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 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.
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 7 years ago.
Improve this question
I'm working on a project using MVC and Entity Framework. For now, what I am doing is that I am using the Controllers to directly do "TryUpdateModel" within their Action methods using the auto-generated Model by the Entity Framework.
My question would be, is this a good / recommended approach? Of course, the Model I am passing still to a repository class for further processing and saving.
I am curious. What if I create a "wrapper" model to the auto-generated one? Can the ViewModel be this "wrapper" model?
Your thoughts are good. It's better to use the wrapper model instead of the autogenerated one. Because autogenerated model have the role of DAO (Data Access Object) and sometimes don't fit with your needs for View Model.
The actual View Model should be the wrapper model. Because sometimes you only want a chunk of your DAOs (autogenerated model).
You should avoid directly updating the model or make sure you explicitly set which properties it's allowed to bind to. The reason is that the method you are using is opening up your code to vulnerability called overposting.
Overposting in short is that a hacker modifies the form to inject properties they are not supposed to be able to update. See here: http://odetocode.com/blogs/scott/archive/2012/03/11/complete-guide-to-mass-assignment-in-asp-net-mvc.aspx
Other than that it's a design desicion like any other. Both ways have some pros and cons. You get less code to write/maintain if you do it your way. But once you need to make changes you have less flexibility because the form and the model need to match, which is not always the best way to build the form.
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
When I read pro and con lists of using Entity Framework (or any modern ORM really), I'm surprised that the following point doesn't arise (self quote):
Using strongly-typed domain entities allows for type checking at
compile-time which essentially performs a verification of all your
database operations. This is something that is not possible with
ADO.NET (whether using inline SQL or stored procedures).
For me, this is one of the biggest advantages of using an ORM. An issue that I come across regularly when dealing with ADO.NET based applications are the run-time errors from SQL. Static checking completely eliminates this.
Could anyone elaborate as to why this isn't hugely relevant to many developers?
Oh it's great.
It's also not free. EF is essentially built on top of ADO.net, it just uses reflection to convert back-and-forth between strongly typed classes and the actual column names. This is fine if your recordset is fairly small, but it's very noticeable when you start dealing with larger sets of data.
Generally this extra lag time isn't important because if, say, the DB takes two seconds to pull the data up to begin with, what difference does an extra millisecond (or even a second) make. But there are situations where speed is critically important, and in those situations you pretty much have to write your own constructs using raw ADO.
The same question was asked here. It includes some good answers.
Programmers.stackexchange.com was a more appropriate place to ask the question.