Asked by:
Get data from database to be used in web app connected to another database

Question
-
User799396372 posted
Hello everyone
I would like to develop an MVC 5 Web App for Management law case. for that i have to build a database for data storage and management.
i need also to employees and department tables data. these tables are existed in HR database.
I want de do CRUD operations in lawcase object with employee and department object without recreate these two table in law case database ?
Is it possible? what is the way for that please ?
Saturday, February 27, 2021 6:57 PM
All replies
-
User1312693872 posted
Hi,Beginner32
Do you mean use Code first and Database first in the same project?
You can just use one or another in the same project, if you already have a database now, then you can only use database first to keep the
Data consistency.
https://docs.microsoft.com/en-us/ef/ef6/modeling/designer/workflows/database-first
https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/workflows/new-database
Best Regards,
Jerry Cai
Monday, March 1, 2021 3:11 AM -
User799396372 posted
Hello
Do you mean use Code first and Database first in the same project?is there another way?
Friday, March 19, 2021 8:26 AM -
User503812343 posted
If the employees and department have fewer data and fewer insert/update/delete operations you can keep that data in Cache object which is fairly fast.
otherwise, you will have to use two different database connections at run time to get the required data from both databases,
Friday, March 19, 2021 8:48 AM -
User1120430333 posted
The only way you can do this is with two database connections to the two different databases, with database objects dealing with the two databases and their respective tables.
You have to implement seperation of concerns using a Data Access Layer (DAL) and using the DAO and DTO patterns. You would also be using a layered style.
Separation of concerns - Wikipedia
Architectural principles | Microsoft Docs
Understanding Separation Of Concern in ASP.NET MVC (c-sharpcorner.com)
The DAO pattern is a DAO on a per table basis that does the CRUD for an individual database table.
Data Access Object (DAO) design pattern in Java - Tutorial Example (javarevisited.blogspot.com)
Data Transfer Object Design Pattern in C# - CodeProject
Chapter 3: Architectural Patterns and Styles | Microsoft Docs
You should understand your various models used in MVC, like the viewmodel as opposed to a data persistence model.
Understanding ViewModel in ASP.NET MVC (dotnettricks.com)
You should understand what the link is talking about below.
Understanding Models, Views, and Controllers (C#) | Microsoft Docs
<copied>
An MVC model contains all of your application logic that is not contained in a view or a controller. The model should contain all of your application business logic, validation logic, and database access logic.
A view should contain only logic related to generating the user interface. A controller should only contain the bare minimum of logic required to return the right view or redirect the user to another action (flow control). Everything else should be contained in the model.
In general, you should strive for fat models and skinny controllers. Your controller methods should contain only a few lines of code. If a controller action gets too fat, then you should consider moving the logic out to a new class in the Models folder.
<end>
The concepts being talked about are being used in ASP.NET MVC solution out on GitHub. The models folder has viewmodel = VM and domain model = DM objects in the Models folder in the ASP.NET MVC project, the presentation layer.
darnold924/PublishingCompany (github.com)
The same kind of concept is being done for a Windows desktop forms solution that is using MVP and a layered style with all layers on the same computer, as opposed to the ASP.NET MVC solution that has a WebAPI sitting between the client-side, and the WebAPI is doing CRUD with the DAL on the behalf of the client-side.
darnold924/PubComanyWinCore (github.com)
Understanding Basics of UI Design Pattern MVC, MVP and MVVM - CodeProject
HTH
Saturday, March 20, 2021 3:40 AM -
User-474980206 posted
You really should have a separate project for each database.
Saturday, March 20, 2021 3:20 PM -
User799396372 posted
Hello
How to reuse these same tables (Employees and Department) in all my futures projects? please.
Tuesday, March 23, 2021 10:49 AM -
User1120430333 posted
You make aclasslib project call it DAL (Data Access Layer that uses the tables. You can then take the created DLL for the DAL and use it in other projects.
U
Tuesday, March 23, 2021 12:43 PM