Solved

Entity Framework 4.0 with tables from 2 different Database Servers

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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