How to work with multiple databases in entity-framework? - entity-framework

I'm working with entity-framework and MVC and i have two databases in the same server.
I just want to do a select in a table in the "database1" then do another select in a table in the "database2" in the same code but i don't know how to configure two diferent databases in my project.
Can someone show me how to configure it to do this? and how to use it in the code?

You have to setup your connection in your database initilizer. In EF6 you have a good support for multiple databases.
Check this link: Using entity framework on multiple databases

Related

Database design for custom objects for SaaS application

I’m looking forward to creating a multitenant-based SASS application. I have defined database design like each tenant using different databases (Postgres) with standard objects(tables) like contact, and accounts. So far clean, I can see many SaaS application supports Custom Object(tables), where customer can create their own objects in real-time and required columns. I would want to support the same. Could someone please explain the backend logic behind that? How can we add new tables for custom objects in the database and refresh the DbContext entity at runtime?
Note: I’m aware for custom fields, many choice JSON-type columns in Postgres, it opens ways to add as many custom columns as JSON type in existing tables. But don’t find any recommended way to do custom object support.
EF doesn't really support adding tables at runtime. You can use ADO.NET queries to work with tables whose schemas aren't known at design-time.

Suitecrm Database schema for multiple companies

How can I separate database using suitecrm.
In My application there is one source code and i want to company wise separate database.
Please help me.
You might need to use seperate installations for keeping them seperate.
Additionally, you can use $sugar_config['db'] variable to dynamically connect with a database of your choice.

Can you connect to two postgres databases in Springboot?

If yes, how?
I am writing a archival project where old data from one database has to be moved to another. For this, I need to connect to two database in a springboot project.
Any pointers would be appreciated.
You need to provide two different DataSources (two different beans).
Take a look at http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-two-datasources

How can I attach membership database to my own database on the fly with EF code first?

Can anyone help me out to solve this issue please :
Well I'm recently building a CMS using ASP.NET MVC 4.5 ,with Entity Framework Code First , so my whole database get created on the fly , now the problem is that I need to use the built-in asp.net membership database without ending up with two databases one for the users and roles managements and one for the CMS management , so how can I solve this issue , any idea ?
Follow the link below, let me know if you have any other questions.
Including Asp.net Simple Membership Tables as Part of Your Entity Framework Model

EF with only a subset of existing tables

I got an existing database with many tables which are accessed using stored procedures only (no O/RM). I'd like to create new tables in this database using Entity Framework and the Code First approach.
Do all the tables in my existing database need to be modelized in my Entity Framework classes? Will I be able to hand-code only the new classes I need in my DbContext? Other tables really need to stay untouched and away from O/RM for the moment.
Note: I'm going to be using the latest EF5.
As for now the Power Tools only allow you to reverse engineer all tables and views in the DB, which can be a problem if you have a big DB, with hundreds of objects, you do not want to reverse engineer.
However, I found an easy workaround for that:
Create a new technical user for the reverse engineering. To this user you only grant permission to the tables and views, that you want to be reverse engineered.
Have fun!
You are under no obligation to map any given table with EF. If you already have a database, you may want to consider reverse-engineering your database with the EF Power Tools available from Microsoft. I did this recently with a MySQL database that I had for testing purposes and it worked quite well!
If you are new to EF an advantage is that the PowerTools write a ton of code for you, which will help you get a grasp on the syntax of Code First. You will need to modify the output but it is a great start. I really believe that this approach will give you the least headache.
The EF PowerTools can be found here: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/