Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:36:15+00:00 2026-06-10T10:36:15+00:00

I am working on a 3-Tier application. Also I am using LINQ to SQL

  • 0

I am working on a 3-Tier application. Also I am using LINQ to SQL for data access.

The DataLayer has a function which returns a table of customers:

public Table<Customer> getCustomers()
{
    DataContext context = new DataContext();
    Table<Customer> customerTable = context.GetTable<Customer>();

    return customerTable;
}

It is provided to the Business-Layer where the results are being passed to the Presentation-Layer as IEnumerable<Customer>:

public IEnumerable<Customer> getCustomers()
{
    CustomerDAL customerDAL = new CustomerDAL();

    return from c in customerDAL.getCustomers() select c;            
}

In the Presentation-Layer I am simply using the IEnumerable for a DatagridView’s DataSource.

What if I had another table like “Information” and the according customerDAL.getInfo() table? Now I want to make a join query in a method in the Business-Layer. I imagined it something like this:

public IEnumerable<Customer> getCustomerInfo()
{
    CustomerDAL customerDAL = new CustomerDAL ();

    return from c in customerDAL.getCustomers()
                  join i in customerDAL.getInfo() on c.id equals i.InfoID
                  select new { c.id, c.Name, i.DateTime, i.Project };
}

The problem is IEnumerable needs the object’s type. My return value isn’t a customer-table anymore, but a combination of a customer- and a info-table. Did I get it right? What would be the right choice for a return value here?

After your advice I created a custom class, CustomerInfo.cs:

public class CustomerInfo
    {        
        string name { get; set; }
        long id { get; set; }
        string dateTime { get; set; }
        string project { get; set; }


        public CustomerInfo(long _id, string _name, string _date, string _project) 
        {
            name = _name;
            id = _id;
            dateTime = _date;
            project = _project;
        }
    }

Then I am calling the exact same method as described by Reed. But in the Presentation-Layer when I set the DataSource I get the exception:

The query contains references to items defined on a different data context.

Actually this is not true all Entity classes are in the same .dbml file. What could be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:36:17+00:00Added an answer on June 10, 2026 at 10:36 am

    Regarding the second error:

    Then I am calling the exact same method as described by Reed. But in the Presentation-Layer when I set the DataSource I get the exception:
    The query contains references to items defined on a different data context.

    Most likely your DAL is instantiating a separate instance of the context for each table that you are returning (Typical in a ActiveRecord patterned implementation). In order for the join to work, both tables need to be retrieved by the same context object. You may want to modify your DAL so that you inject the context in the constructor of the DALs so that you can centralize the lifetime of the context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a small N-Tier application in C# which uses Linq-to-Entities
I am working on three tier application. 1.UI 2.BUZ 3.SQL I want to integrate
The project I'm working on has a bunch of service-tier unit tests using Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute.
I am working on an n-tier web project, The data access layer is in
The project I'm working is using n-tier architecture. Our layers are as follows: Data
I'm working with an n-Tier application using WinForm and WCF Engine Service (Windows Service)
I am working on an n-Tier application using WCF between the layers such that:
I am working on windows forms application using c#.net. i have developed an application(3-tier)
We are working on a 3-tier application, and we've been allowed to use the
I'm working on a fairly straight forward multi-tier application (WPF, WCF, EF 4, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.