Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ER multiple DB

Posted on 2014-08-06
5
Medium Priority
?
105 Views
Last Modified: 2014-08-06
I'm using ER 4.0/4.5. My solution has a few projects. Aomng those projects, two of them have mapped two databases. Or say there are .edmx in two different projects in one solution. My question is - Can entityframework handle multiple database accessing? How? I need get data from two EF.  Thanks.
0
Comment
Question by:minglelinch
  • 3
  • 2
5 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 40243480
Hi minglelinch;

You can not access the two databases through a single DbContext. You will need to instantiate one DbContext for each database and query each database separately and pull down the needed data and perform local queries on the two different result sets.
0
 
LVL 1

Author Comment

by:minglelinch
ID: 40243535
Thanks for your post. But I'm still wondering about "perform local queries on the two different result sets". How to do this or any further detail?
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 40243571
Hi minglelinch;

Let's give a hypothetical example. Lets assume you have two databases. In database A you have a table of Customers in database B you have the orders for the customers in database A. Let assume that you want to query all the customers that are located in New York City as well as all there Orders. The first thing to do is retrieve a collection of customers from database A and execute the query. The next thing to do is to retrieve a collection of orders using the CustomerID and execute that query. Now in local memory you have two collections one of Customers and the other of Orders. Now you can perform a Linq to Object query between the two collections to arrive at a final result set.
0
 
LVL 1

Author Closing Comment

by:minglelinch
ID: 40244796
Thanks for the post.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 40244872
Not a problem minglelinch, glad to help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question