Solved

Entity Framework 4.0 with tables from 2 different Database Servers

Posted on 2014-01-27
4
256 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

728 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