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 323277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:00:58+00:00 2026-05-12T09:00:58+00:00

I’m using LINQ to model my database, but I’m writing it by hand (Steve

  • 0

I’m using LINQ to model my database, but I’m writing it by hand (Steve Sanderson recommends this in his ASP.NET MVC book). What I need to know is what’s happening when you create an EntityRef, and how it’s referenced. If I create my queries manually (without using LINQ), but use LINQ to model it, and I bring back just the ID of something, then reference the actual table column using EntityRef in the view, does it do the join, or does it re-query the database for that bit of information?

To clear things up, if I have this in my repository:

public IEnumerable<MyTable> ListMyTable(int? myColumnVar)
{
  string query = "SELECT * FROM MyTable WHERE MyColumn = {0}";

  return this.ExecuteQuery<MyTable>(query, myColumnVar);
}

and then in my controller I do this:

IEnumerable<MyTable> mytables = _contractsControlService.ListMyTable(1);

return View(mytables);

then in my view I do things like

<%=tbl.Ref.MyColumn %>

I’m referencing something set out by the LINQ model, but isn’t actually in the table output. How does it get that data?

To clear things up further, we’re using systems which require ultimate speed, so the LINQ-to-SQL is too slow for us, hence why we’re using direct queries in our repository. I wouldn’t mind using this EntityRef business if only I knew what was happening underneath.

  • 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-05-12T09:00:58+00:00Added an answer on May 12, 2026 at 9:00 am

    You have most likely used the Object Relational designer to create an entity class for the Ref entity and an association between the MyTable and the Ref entity. You can also do that manually by creating the appropriate entity classes and using attributes to map the classes to the database schema. You can read the details in How to: Customize Entity Classes by Using the Code Editor (LINQ to SQL) on MSDN.

    In your generated (or handwritten) code you will find some attributes:

    [Table(Name="dbo.Ref")]
    public partial class Ref : INotifyPropertyChanging, INotifyPropertyChanged
    

    and

    public partial class MyTable: INotifyPropertyChanging, INotifyPropertyChanged
    {
    
      [Association(Name="Ref_MyTable", Storage="_Ref", ThisKey="RefId",
        OtherKey="Id", IsForeignKey=true)]
      public Ref Ref
      {
         get
         ...
    

    The entity classes combined with the attributes enables the Linq-to-Sql framework to retrieve entity classes directly from the database.

    If you want to monitor the SQL genereated by Linq-to-Sql you can assign the DataContext.Log property:

    context.Log = Console.Out;
    

    In your example, navigating from MyTable to Ref, probably generates SQL along these lines:

    SELECT Id, Field1, Field2, Field3
    FROM Ref
    WHERE Id = @RefId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.