Using MVC with multiple different databases - asp.net-mvc

I have used MVC thus far in a traditional EF sense by creating POCO first objects and then adding this to a database context but I have a new problem in that I am trying to recreate a legacy system but using the MVC framework but it uses a connection to multiple different databases and tables.
In the legacy solution they use Enterprise library to create the link to databases but I am not sure that this is the best option available and was wondering what are the options open for dbconext in regards to different database connections at the same time, is this possible?

The question is nothing to do with MVC. Besides, ASP.Net MVC (Presentation Layer) should not even need to know about what kind of ORM or database at Data Access Layer.
Back to original question, it is not worth using Entity Framework, if you have to query two databases at the same time.
I suggest you want to look at other ORM like Dapper.

Related

Best Approach for shared entities (Tables) among multiple applications

We are working on suite of applications in our company. Each applications have different business logic but share some structures. For example one application is for "IT services" and another one is for "package handling system" among different buildings of the company. We want to create each application with separate asp.net mvc projects (Entity framework Code-First). But the problem is that all of the applications have some similar entities. For example all of them have People, Buildings and Floors Entities in their dbContext. and also have some other tables that have relations to this similar tables
What is the best approach to designing this applications?
Create a single database for all of the applications? what is side-effects?
Create separate Database for each application and duplicate the similar Tables? (currently we working on this but we should write some SQL server jobs to always sync this tables. so I don't think its a good approach)
Create a database for shared tables and another databases for each application. This will cause to lose relations between tables and also produces multi-Context applications (I prefer this but I read that with Code-First EF and linq, it is not possible to query cross multiple contexts)
or something else ?
I am very interesting for Db management system. I like your 3 aproach firstly. All of them different advantages and disadvantages. If you have huge datas on this db may you can use seperate Database like solution like 2. But you have to develop sync mechanism that you said. If we look at another advantge of seperate db that when one db is failed or broken, another db can work :) but some of departmant data can be unavaible until error fixed. This can be good for huge systems.
Lastyly, "Create a database for shared tables and another databases for each application ", this idea is so good :)
May you can use N-Tier artitecture at least 3 tier(Business-Presentation-Data)and
Busines==> Your Worker Functions
Data Layer==> Many Db Context
Presentation ==> MVC project
I think the solution 3 and Lose Coupling Connection with N-Tier Artch is best way.
Lastly may you seach;
Unit Of work, Ninject Freamwork, N-Tier topics
Note: Alwasy the code-first :) I like Code First style to much :D
Have a nice day :)
If you want I can show a few N-Tier structure Lesson Link around "CodeProject.com" and Stackoverflow

ASP MVC application design needing to access multiple databases

I am trying to design an .NET MVC application and the application needs to access data from multiple databases. I the only way to do the low level database I/O is by calling MS SQL stored procedures. What I think is the best way to go is to develop the data layer using a combination of WCF as the lowest level calling the actual stored procedures. From there I feel that an Entity Framework layer be setup to be used for the actual MVC design. Can anyone give me a few I ideas to the best way for a successful design?
Since you are going to use entity framework so I think you can go with multiple data access layer.
DALDatabase1
DALDatabase2
Both these database can have their own repositories. This will be the cleaner approach.
You use one layer as well but that will going to be messy in future.

New MVC 4 project based off ASP.net web forum application that uses Subsonic as ORM...where to start....?

I have been given the task of trying to convert our company's existing ASP.NET Web Forms application into an MVC 4 application (as an R&D starting project). I have a little experience with MVC 2, but my issue is trying to actually get started. We have existing stored procedures that we access via Subsonic as our ORM (so that they can be called in our code). We also have a Data Access Layer that is tied in with Subsonic.
I know this is kind of a vauge question, but is there a known way I can use our existing stored procs and tables with a different ORM (such as NHibernate or something) to start creating this MVC application?
Thanks for any help provided.
There should be no reason that the SP's need to change just because the ORM changes; you may want to to improve some of what you are doing and rewrite some of them, but not because the ORM changed.

Datawarehousing with ASP.NET MVC

On one server there are more than 20 databases with identical structure but different data. I need to collect some of the data (the same queries) from all databases and store in new database which is located on another server. I decided to use ASP.NET MVC 2 but it doesn't seem logical to use more than 20 "LINQ to SQL Classes" (.dbml) files because the structure is the same for all databases and it's repeating if I use so many of these files. Is there a simple way to use one .dbml file (for remote databases) but change only connection string?
I agree that you really wouldn't want to use MVC as that is a web framework and has nothing to do with moving data around.
You can also look into using an ETL tool to accomplish this task. I have used RhinoETL in the past successfully to accomplish something similar.
There are also multiple posts on this site discussing ETL tools. For example, check the following link - https://stackoverflow.com/questions/51198/what-etl-tool-do-you-use
According to this, you can pass in a connection string with the dataContext constructor. So theoretically, you should be able to have one dbml file, but you can instantiate multiple instances of your data context, each with a different database connection string specified. Each context should then point to their respective database and allow you to work with multiple databases.
Why do you want to use ASP.NET MVC at all? ASP.NET is for web UI, not data warehousing (except when you need to display cubes). Looks like you use SQL Server. If that is true you can utilize Integration Services (ex DTS) to do the job.

How to work with ASP.NET MVC and ODBC 2.0

I am starting out on a project that will involve ASP.NET MVC using a legacy ODBC 2.0 compliant database. The goal is to replace current system functionality with a web front end over a period of maybe a year then swap out the backend with SQL Server.
The plan would be to code against SQL server then insert some shim into the repository classes to use ODBC instead. Is it even feasible to do this ? Entity Framework doesn't have built in support for ODBC.
Any thoughts or advice would be appreciated.
I personally use NHibernate with MVC. Originally I picked it up because our database doesn't support EF but enjoy it enough that even if we moved to SQL Server I'd keep NHibernate.
The learning curve is kinda weird. It is definitely steep to become an expert, but it is interesting in that it is pretty organic to let it handle more and more of the work for you as you get comfortable with certain layers.
So for your case NHibernate probably supports your database, can be used as a simple data access layer (just returning DTOs), provides a database agnostic interface and can support SQL Server when the time comes. If you end up wanting more out of NHibernate it is there when the time comes.
There's nothing to stop you writing your own data access layer, to query the ODBC Database. You could also make your own entity layer so that the MVC model can populate your entities using the data layer, and return these objects to the controller.
Basically, have a data access and entities layer under your mvc app, then you can replace these entities, with entity framework, or nhibernate entities, at a later date.
This way of doing it means that your MVC app doesn't need to know what database it is using, it also means that you should have an easy time when you switch an entity later.

Resources