"properly calling the database from model in an mvc application?" Code Answer
Answers related to “properly calling the database from model in an mvc application?”
- An example of an MVC controller
- Can a model link to a View in the database instead of a table in CakePHP?
- Calling model function in view codeigniter
- How to save, handle the order total amount in an orders, ordersDetails schema?
- PHP MVC Application loosing path references to jss and css files
- PHP - The best way to load Database object from Model, but to have only one instance?
- How would you cache content in an MVC project
- Change the Database Connection Dynamically in Laravel
- Is $view in an MVC php program a proper use of global variables?
- Pass a variable from view to model in mvc
- How to connect to SQL Server database from JavaScript in the browser?
- How can I implement an Access Control List in my Web MVC application?
- getting the values from a nested complex object that is passed to a partial view
- How to cache data in a MVC application
- How to use sessions in an ASP.NET MVC 4 application?
- How do I consume the JSON POST data in an Express application
- Display image from database in asp mvc
- Why can't I use System.IO.File methods in an MVC controller?
- Where to put view-specific javascript files in an ASP.NET MVC application?
- MVC3 and Code First Migrations - “model backing the 'blah' context has changed since the database was created”
- How do I get the collection of Model State Errors in ASP.NET MVC?
- Cannot attach the file *.mdf as database
- ASP.Net MVC: How to display a byte array image from model
- Extracting files from an Attachment field in an Access database
- HTML button calling an MVC Controller and Action method
- What is the difference (if any) between Html.Partial(view, model) and Html.RenderPartial(view,model) in MVC2?
- How do I set the request timeout for one controller action in an asp.net mvc application
- Adding sub-directory to “View/Shared” folder in ASP.Net MVC and calling the view
- ASP.NET MVC DropDownListFor not selecting value from model
- There is already an object named 'AspNetRoles' in the database
- where should i place the js script files in a mvc application so jquery works well?
- How to implement In-App Billing in an Android application?
- What is the proper way to send an HTTP 404 response from an ASP.NET MVC action?
- The model backing the 'ApplicationDbContext' context has changed since the database was created
- how to get the images from device in android java application
- .NET MVC : Calling RedirectToAction passing a model?
- Multiple languages in an ASP.NET MVC application?
- Should a service layer return view models for an MVC application?
- Default value in an asp.net mvc view model
- MVC DropDownListFor not selecting value from model
- Ruby on Rails: Is it better to validate in the model or the database?
- How to implement Google reCaptcha in an MVC3 application?
- Best way to filter domain objects for json output in an ASP.NET MVC application
- Can I customise my data text field in an MVC SelectList for use with the HtmlHelper.DropDownList without having to...
- What is Model in ModelAndView from Spring MVC?
- Castle Windsor IoC in an MVC application
- Passing model attribute during redirect in spring MVC and avoiding the same in URL
- ASP.NET MVC passing an ID in an ActionLink to the controller
- Entity Framework 5 Migrations: Setting up an initial migration and single seed of the database
- Why do Rails migrations define foreign keys in the application but not in the database?
- ASP.NET MVC CheckBoxList from model with List Property
- Specifying Roles in web.config of an asp.net MVC application
- how to pass a razor value to a jquery function, in an mvc view
- Fixing Null EntityManger in Spring MVC application?
- What exactly is the model in MVC
- “Run Custom Tool” for resx files in MVC2 project (from an external application/script)
- How to get the values from the Model and into Views Javascript (Visual Studio 2015 mvc)
- In a MVC application, should the controller or the model handle data access?
- How to transfer ASP.NET MVC Database from LocalDb to SQL Server?
- How to do Migration when Generate database from model in Entity Framework Model First
- How to display HTML stored in a database from an ASP.NET MVC view?
- What are the advantages of using an MVC framework over e.g. Drupal to build a large website?
- Is the Rails update_attributes method the best choice for doing an update of a model in the database?
- should the user's Account balance be stored in the database or calculated dynamically?
- How to pass Enum from view to model ASP.Net MVC
- Spring Security 3.2: @Autowire doesn't work with java configuration and custom AuthenticationProvider in Spring MVC...
- How to push the data from database to application?
- Get the “Key” for a strongly typed model in the controller
- How to setup MVC 5 unobtrusive validation correctly when appending the form from an AJAX call?
- get value from @Model inside jquery script
- Change the model in OnActionExecuting event
- How can I host multiple websites in IIS 7 and use the same MVC application for all them?
- What should be stored in source control for an Asp.Net Core MVC application?
- How can I call an MVC FileContentResult by Jquery and get it to prompt the user to save on it's return?
- Unable to retrieve metadata - MVC application
- how to remove the controller name from the url using rout in MVC
- Calling an asp.net console application from my asp.net mvc web application
- Downloading files from the database in Asp.Net Mvc
- Possible to create new Database from Point In Time Restore using Azure ARMs SqlManagementClient?
- Best way to do partial update to ASP.NET MVC model ('merge' user submitted form with model)
- How does a new ASP.NET MVC 5 application know how to create a database and how does the Account Controller access...
- What is the easiest way to get the property value from a passed lambda expression in an extension method for...
- What naming convention do you use for the service layer in a Spring MVC application?
- Minify HTML output from an ASP.Net MVC Application
- Should I use the built-in membership provider for an ASP .NET MVC application?
- Integrate Angular and Webpack in an ASP.NET MVC Application
- How to separate model, view and controller in an ASP.NET MVC app into different assemblies
- Why can I remove ExtensionlessUrlHandler from an MVC application without any ill effects?
- Import data from excel spreadsheet to django model
- How do you access the current RouteData from View in .net MVC?
- In Laravel, how do I retrieve a random user_id from the Users table for Model Factory seeding data generation?
- How do I handle uncaught exceptions in an ASP.NET MVC 3 application?
- Can anybody explain MVC in terms of UItableview when getting data for the table from the internet?
- Download album art from internet in an android application
- How can you get the “real” HttpContext within an ASP.NET MVC application?
- What are the best practices around setting global model attributes in Spring MVC?
- How to debug an Asp.Net Mvc Application in Visual Studio 2012 from a remote computer
- Connecting to an MSSQL database from a Ruby on Rails application running on Ubuntu
- How do I avoid having the database password stored in plaintext in sourcecode?
- How can I create a generic view model in MVC?
- Accessing the database of one application from another application
- Where to put PassportJs local strategy in an express application?
- How to localize the Controller names and actions in an ASP.NET MVC application?
- Finding Locale from Controller in Spring MVC
- How to model tags in the database?
- How to cleanly get user input from the middle of model's method in Model-View-Viewmodel architecture?
- How should one maintain a database connection in an ASP.NET MVC application?
- In a RESTful application, how do we differentiate between an “action” and an HTTP verb (GET, POST, PUT, DELETE)?
- Trouble with TreeStore in ExtJS 4.0 MVC application
- How to allow anonymous twitter connections in an MVC configuration
- How to get the raw 'created_at' value in the database (not an object cast to an ActiveSupport::TimeWithZone)
- Spring MVC, calling another controller from Inside a controller
- Can a C# named Tuple be used as an MVC page model type?
- Update Database after Model Changes - Entity Framework 7
- How to display a list of objects in an MVC View?
- Generate POCO classes from model using T4 templates vs. EF4.1 simplified API Model First approach
- MVC Rendering (RenderPartial, RenderAction) Html from another MVC Application
- Testing a controller with an auto wired component is null when calling the controller from a test case
- Making an async call in an MVC 5 action filter
- I am getting an extra empty {} json object along with a && before my output from a simple spring mvc json service
- How do I access other attribute values from inside a custom ValidationAttribute in an asp.net mvc 2 application?
- Create CheckboxFor MVC helper with title attribute from model description
- How can I create a local user profile for the anonymous user of an ASP.Net MVC application under IIS 7?
- How to properly configure Stomp and SockJS endpoint in Spring MVC?
- CodeIgniter: Can't load database from within a model
- Sending/POSTing collection data from an HTML/Razor form to an MVC action argument model
- How to inject User Manager to Account Controller with default Identity Model in Identity 2 using Ninject
- Create Views for object properties in model in MVC 3 application?
- Is there a way to set the local time, which may be different than the server's time, in an ASP.NET MVC3 application?
- How to display text in an MVC view with htmlattrbutes
- Add Trailing Slash for MVC Application
- Calling a method in model from layout in Zendframework 2
- Calling the Session before any Controller Action is run in MVC
- Debug a C++ DLL used in ASP MVC application
- Formatting dates in an MVC Dropdown
- What is the difference between model.fit() an model.evaluate() in Keras?
- jQuery in an ASP.net MVC application using Master Pages
- Is it possible to disable authorization on one action in an MVC controller?
- ASP.NET Web API Generate all parameters from model - help pages
- Where does input validation belong in an MVC application?
- Where should I create the Unit of Work instance in an ASP.Net MVC 3 application?
- Where to put Entity Framework Data Model in MVC application?
- Is my ASP.NET MVC application structured properly?
- Passing multiple parameters in an MVC Ajax.ActionLink
- Capybara+Selemium: How to initialize database in an integration test code and make it visible in Rails application?
- Designing an MVC repository using ViewModels
- MVC 4 - Use a different model in partial view
- Display error message on the view from controller asp.net mvc 5
- How do I add placeholder text from the model into a MVC view?
- What's the best way for the client app to immediately react to an update in the database?
- How to build a data model for an access control list (ACL)
- How to get base URL of an MVC application using javascript
- What is the use of an IoC framework in an MVC application?
- Using AutoMapper in the Edit action method in an MVC3 application
- Configuring NHibernate second level caching in an MVC app
- How to check the Database Connection leakage in Java EE application?
- Can the MVC Design Pattern / architectural pattern be used in Desktop Application Development?
- Communication between the View and Model in MVC
- Is it safe to use reflection and enums for logic control of MVC application access?
- Is User.Identity.GetUserId cached or does it fetch from the database every time?
- Get items from listbox in controller MVC ASP 4
- How to authenticate in an ASP.NET MVC application from a console application
- How does the session scope of a bean work in a Spring MVC application?
- What happens behind the scenes of deploying a Spring MVC application to tomcat outside of eclipse?
- What is the PreserveLoginUrl appSetting key/value in an ASP.NET MVC application?
- A smart way to handle Return URLs in an MVC environment
- How to share the most code between a WPF and an ASP.NET MVC application?
- How to prevent from DataAnnotations Attributes being deleted in DataBase First Model
- What is the best practice to include js/css files in an enterprise application framework?
- How can I generate the database from .edmx file in Entity Framework?
- When should I use HttpDelete or HttpPut in an asp.net mvc application
- Formatting currency using display template in MVC
- Editing an object in entity framework and saving it to the database in ASP.NET MVC 2.0
- What should own the model in an MVC pattern?
- How to clear the post data for a textbox in an ASP.NET MVC application?
- Using Spotlight as the “database” of an application
- Understanding how Nop Commerce settings are loaded from the database
- iOS MVC - How to pass data from model to controller?
- Passing Model to Controller from View in ASP.NET MVC
- Including Pre-Compiled Views in an ASP.NET MVC Web Application
- How to do a form POST to an MVC 3 application and obtain the deserialized class?
- In ASP.Net MVC, what is the best way to do an update from a dialog?
- Passing UISegmentedControl values from FlipSideViewController in an Utility application to the mainviewcontroller…
- What is the most efficient way to perform the reverse of Server.MapPath in an ASP.Net Application
- How can I retrieve the instrumentation key for an Application Insights instance in an Azure Resource Group Template?
- Pre-populate HTML5 offline appcache for a UIWebView in an iOS application
- MVC4 scaffolding of database-first Entity Framework model in Visual Studio 2012
- HttpApplicationState not available in an MVC controller
- How to find the exceptions / errors when TryUpdateModel fails to update model in asp.net mvc 3
- Actual html markup not html entity when inserted from model property in mvc3
- How can I properly Mock the KeysCollection in HttpSessionStateBase?
- Put ASP.NET MVC application in subdirectory of main MVC application?
- Pdf file from database to view in asp.net mvc
- What is the best way to migrate an existing messy webapp to elegant MVC?
- Why is a value that I update in my model inside an MVC3 controller not rendered on the client?
- There is already an object named '__MigrationHistory' in the database
- Hosting a WCF Service in an MVC application outside of Areas
- Use an Oracle database with forms authentication in an MVC3 application
- Where should I create my Entity Framework context object in an MVC app?
- How to conditionally set a model in asp.net MVC view?
- Google Analytics Code - Is the correct place to put it in an MVC 5 app?
- How can I isolate users' data in ASP.net MVC application?
- What are the responsibilities of the components in an MVC pattern for a simple login
- Log out button not working in mvc application
- Accessing the property of a model in ASP.NET MVC View
- What is the "model" in the MVC pattern?
- How to differentiate between first time google Sign-In and successive google sign-In in an android application?
- How to set the welcome-file when developing spring mvc application with pure Java based configuration and no web.xml?
- ASP.NET MVC application reading data from SQLite database
- Create new database programmatically in Asp.Net MVC application?
- Serving contain to sub domains from an MVC / IIS web application
- How can I export to CSV in an ASP.NET MVC application?
- How to Manipulate Application Pool Configurations in an MVC Application
- Bind value to model in Asp.Net MVC Application Part 2
- How do I bind XML Attributes to the action model in MVC Web API?
- Search model is getting cleared for second page request in PagedList.MVC in MVC
- Does a new() EF Context in the constructor of a controller properly handle the disposal?
- Rails calling User record from Friends model
- How to deploy an ASP.NET MVC application on build using MSBuild in Visual Studio 2015?
- Sorting table row redirects the whole page in my MVC application
- Getting the index of the leftmost active bit in an integer instantly
- Issue extending the base EDMX model and calling the functions in the data model
- How do I perform an Enum binding to a view's model in .NET's MVC?
- Present a thumbnail image of a remote web site page in an asp.net mvc application
- How to pass a list of selected objects from javascript in an action in MVC?
- Is the "Async" suffix required in the name of an async ASP.NET MVC 4 action?
- Can I get the Process ID of a worker process in a web application?
- In an MFC application, what's the easiest way to copy a file from one directory to another?
- Thunderdome MVC- Why one-model-in in MVC?
- What happens if I leave a database connection open in an ASP.NET web page
- How do I stop this cascading delete from happening in Django?
- Is it possible to select an Action with AttributeRouting in .NET MVC based on the Media Type of the Accept header?
- Is it possible to disable authentication Filter on one action in an MVC 5 controller?
- Is it possible to use Neo4j database in an Android application?
- Swift / Firebase: How do I properly store a Facebook user into Firebase database when they create an account?
- Exclude Fields From Model Validation
- Entitiy Framework: "Update Database from Model" instead of "Generate Database from Model"
- How can I access the entire query string in an ASP.net controller action
- How to Start a Java MVC Application With a Swing GUI
- Calling Jsp page from controller in Spring MVC
- Why are there two web.config files in my MVC application
- How to validate whitespaces using jquery/ajax in an MVC view
- Why SQLite database cleared on clearing data of application from Application Management?
- Connect a C# MVC application to a remote SQL Server database
- what is the difference between the asp.net mvc application and asp.net web application
- Why are messages pushed from an MVC app with SignalR not getting through to the client?
- How to get the value from a kendo Editor in my model
- Sending a model containing files from an MVC site to a Web Api site
- Correct external javascript-per-view file placement in an ASP .NET MVC Application
- How can I set table column widths in an MVC view?
Only authorized users can answer the search term. Please sign in first, or register a free account.
Model
itself should not contain any SQL. Ever. It is meant to only contain domain business logic.The approach i would recommend is to separate the responsibilities, which are not strictly "business logic" into two other other sets of constructs : Domain Objects and Data Mappers.
For example, if you are making a blog, then the Model will not be Post. Instead most likely the model will be Blog , and this model will deal with multiple
Domain Objects
: multiple instances of Post, Comment, User and maybe other objects.In your model, the domain objects should not know how to store themselves in database. Or even be aware of the existence of any form of storage. That is a responsibility of
Data Mappers
. All you should do in the Model is to call$mapper->store( $comment );
. And the data mapper should know how to store one specific type of domain objects, and win which table to put the information ( usually the storage of of single domain object actually affects multiple tables ).Some code
(only relevant fragments from files):
_
in example isprotected
from
/application/bootstrap.php
from
/framework/classes/ModelFactory.php
file
/application/controllers/SomeController.php
file
/application/models/FooModel.php
I hope this will help you understand the separation between DB logic and business logic ( and actually , presentation logic too )
Few notes
Model should never extend Database or ORM, because Model is not a subset of them. By extending a class, you are declaring that has all the characteristics of the superclass, but with minor exceptions.
Besides the obvious logic-issues, if your Model is tightly coupled with underlaying Database, it makes the code extremely hard to test (talking about Unit Testing (video)).
I personally think, that ORMs are useless and in large project - even harmful. Problem stems from the fact that ORMs are trying to bridge two completely different ways of approaching problems : OOP and SQL.
If you start project with ORM then, after short learning curve, you are able to write simple queries very fast. But by the time you start hitting the ORM's limitations and problems, you are already completely invested in the use of ORM ( maybe even new people were hired , who were really good at your chosen , but sucked at plain SQL ). You end up in situation where every new DB related issue take more and more time to solve. And if you have been using ORM based on ActiveRecord pattern, then the problems directly influence your Models.
Uncle Bob calls this "technical debt".
Few books
loosely related to subject