Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am learning MVC. In this tutorial, entity framework is used form the 'model' part. I am used to OOP in programming. So, i would like to use custom objects instead of entity framework. Is it possible at all?
Sorry if this a foolish question.
an mvc action injects what it wants in a view.
return View("test");
A razor view can display whatever was injected in it.
<body>#Model</body>
Is it possible at all?
Of course, MVC is in no way bound to Entity Framework. It's even advisable to create your own ViewModels, instead of using entity classes for that.
Yes, you can use custom object as model but you need also a layer to access real data.
EF allows you to create model and provides a framework to access/modify data.
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 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
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 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 8 years ago.
Improve this question
I need your opinion on which is better. In an ASP.net MVC project, is it recommended to have one DataModel for my whole database or one for each table in my database?
Note : I'm using EF dataFirst Model with a oracle database.
Lolz thats a nice question. I think you are new to MVC and EF.
Use one DataModel for the whole Database. Entity Frame work supports Oracle databse.
One DbContext represents one database. But, you can have mutliple databse in your project. So, you will have their respective DbContext's.
there are three approch to work with entity framework :
Model First
Data First
Code First
Configuring and using different approches are explained here
https://www.simple-talk.com/dotnet/.net-framework/different-approaches-of-entity-framework/
But, I personally prefer Database First.
If you want to learn more abt ASP.NET MVC with EF look here, Its with Data First
http://www.codeproject.com/Articles/695850/Complete-CRUD-Operations-in-MVC