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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:08:36+00:00 2026-05-24T17:08:36+00:00

I am building a new project from scratch. I created a db where I

  • 0

I am building a new project from scratch.
I created a db where I have consistently applied a db structure that I explain with a short self-explanatory example:

Table Item -> (Id, Name) -> Contains general information

Table ItemInfo -> (Item_Id, Language, Description) -> Contains the language dependent information.

Id and Item_Id are connected with a foreign key relationship.

My idea was to model it in a way that I would end up using only a single POCO object “Item” populated through Entity Framework. This object would contain only the public properties: Id, Name and Description.
The language will be hidden to the code using this object, the object itself should have the responsibility to give the correct description depending on a global variable that contains the language.

I have tried a few ways to do this and always ended up having problems because Entity Framework wouldn’t allow this scenario. I always had to retrieve info for ALL languages and not only the current one or use 2 different queries.

So at the end the solution I started to use was to let a T4 template create both Item and ItemInfo and then I manually added a code similar to this:

public partial class Item
{
    private ItemInfo _itemInfo = null;
    private ItemInfo itemInfo
    {
        get
        {
            if (_itemInfo == null) _itemInfo = ItemInfoes.Single(p => p.Language == GlobalContext.Language);
            return _itemInfo;
        }
    }
    public Description 
    {
        get { return itemInfo.Description; } 
        set { itemInfo.Description = value;}
    }
}

With this code I added the additional properties from ItemInfo to Item and selected the correct language as per my requirements.
Do you think this is a good solution? How would you solve this problem instead?

However, running sql profiler I can see that 2 different sql queries are used to populate the Item object, one that queries the Item table and another that queries the ItemInfo.

Can the same scenario be achieved with a single query that does a join between the 2 tables? (I am afraid of the long term performance hit and also this is how I would do it without an ORM).

Any suggestion will be welcome, I have many years of programming experience but I am a newbie with Entity Framework and ORMs in general.

Please help.

  • 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-24T17:08:36+00:00Added an answer on May 24, 2026 at 5:08 pm

    You’re not showing how you fetch the Item objects, but generally I don’t see a problem with fetching everything in one query. You’ve got several options.
    You can do a projection (but not onto a mapped entity – in this example I project onto an anonymous object):

    context.
    Items.
    Select(item => new 
                   {
                       Id = item.Id,
                       Name = item.Name,
                       Description = item.
                                     ItemInfo.
                                     Where(info => info.Language == YourGlobalLang).
                                     Select(info => info.Description).
                                     FirstOrDefault()
                   };
    

    (This has been edited to use FirstOrDefault instead of Single – see comment discussion with @Craig Stuntz)

    This will return a list of all Items – you can add a Where clause to filter.

    Or you can fetch it the other way around (starting with ItemInfo):

    ItemInfo itemInfo = context.
                        ItemInfoes.
                        Include(info => info.Item).
                        SingleOrDefault(info => info.Language == YourGlobalLang && 
                                                info.Item.Id == itemIdToFetch);
    

    After that you can access the item object itself:

    Item item = itemInfo.Item;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to start a new project that's building web apps from scratch. I
I have been tasked with building a new web project from scratch, with the
I'm starting a new project from scratch and have written User Stores to describe
We have a new project, building a fully featured facebook App on an embedded
just started building out a rails project from scratch after months of re-purposing of
I am getting ready to start building a new web project in my spare
I have a dedicated server and I'm in need for building new version of
When building my Xcode project I am receiving a Linker error that I cannot
I'm building a new project and I'm having some debate over how it needs
Am wondering, when a new project arrives, say building a social networking website, how

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.