Solved

Entity Framework 4.0 with tables from 2 different Database Servers

Posted on 2014-01-27
4
252 Views
Last Modified: 2014-02-02
I am new to EF and am trying to develop a small application using MVC and EF.  My application needs to display a list of employees that exist in a table stored in MS SQL Server 2008.  The table has the following fields:

ENL_Contacts Table
ENL_ContactID (PK, int, not null)
ENL_EMP_ProfileID (int, not null)
ENL_GroupNameID (int, not null)

The ENL_GroupNameID exists in another MS SQL Server table and is in the same model as the ENL_Contacts Table.  The ENL_EMP_ProfileID is a key into an Employee Table that exists in an Oracle DB.  I created a second model that brings in the Employee Table from the Oracle DB.

The EMP_Employee Table in the Oracle DB contains the following fields that are needed by my application:

EMP_Employee Table
EmployeeID (PK, int, not null)
FirstName (varchar(50), not null)
LastName (varchar(50), not null)
(the rest of the fields are not displayed)

How can I create a "View" that joins the ENL_Contacts Table from the ENL Model with the Employee Table from the EMP Model?

I want to be able to display the following:
ENL_ContactID, ENL_EMP_ProfileID, LastName, FirstName, ENL_GroupNameID

Any help or suggestions is greatly appreciated.
0
Comment
Question by:dyarosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 11

Expert Comment

by:jasonduan
ID: 39812255
You can create a "linked server", then create a view, and map the view to EF.
0
 

Author Comment

by:dyarosh
ID: 39812478
Does creating a "linked server" require doing something on the SQL Server or Oracle Server?  If yes I won't be able to do that.
0
 

Accepted Solution

by:
dyarosh earned 0 total points
ID: 39814861
I ended up solving my problem by adding a field to my SQL Server model and calling it EmployeeName.  I then in the get call a method in another class to retrieve the EmployeeName based on the EmployeeProfileID.  Here is my code for anyone who may need to do something similar.

using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using IntranetSupportTeam_i21Login;
using EmployeeProfileDatabase;
using System;

namespace ENL.Models
{
    // ENL_MultiGroup_Contacts
    [MetadataType(typeof(ENL_MultiGroup_ContactsMetadata))]
    public partial class ENL_MultiGroup_Contacts 
    {
        public string EmployeeName
        {
            get
            {
                string connectionString;
                i21Login Login = new i21Login();
                connectionString = Login.GetConnectionString("ORACLE");

                EMPDatabase EMPData = new EMPDatabase(connectionString.ToString());
                return EMPData.GetEmployeeName(Convert.ToDecimal(EmployeeProfileID), false);
            }
            set { }
        }
    
    }

    public class ENL_MultiGroup_ContactsMetadata
    {
        [UIHint("PrimaryKey")]
        [DisplayName("ID")]
        public int MultiGroupContactID { get; set; }

        [Required(ErrorMessage = "* Employee is required")]
        [DisplayName("Profile ID")]
        [UIHint("int")]
        public int EmployeeProfileID { get; set; }

        [DisplayName("Group Name ID")]
        [UIHint("int")]
        [Required(ErrorMessage = "* Group Name is required")]
        public int ENLGroupNameID { get; set; }

        [DisplayName("Active?")]
        [UIHint("bool")]
        public bool IsActive { get; set; }

        [DisplayName("Employee Name")]
        public string EmployeeName { get; set; }
    }
}

Open in new window

0
 

Author Closing Comment

by:dyarosh
ID: 39827443
I did not get a response that addressed the problem so I came up with another solution.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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