Solved

Entity Framework 4.0 with tables from 2 different Database Servers

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now