Solved

Entity Framework 4.0 with tables from 2 different Database Servers

Posted on 2014-01-27
4
239 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
Comment Utility
You can create a "linked server", then create a view, and map the view to EF.
0
 

Author Comment

by:dyarosh
Comment Utility
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
Comment Utility
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
Comment Utility
I did not get a response that addressed the problem so I came up with another solution.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

10 Experts available now in Live!

Get 1:1 Help Now