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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:28:28+00:00 2026-06-14T12:28:28+00:00

Given this code first data model, how would i configure or implement a LocalizedName

  • 0

Given this code first data model, how would i configure or implement a LocalizedName navigation property on the Product entity, that uses the LocalNameKeyproperty on a Product instance for one of the keys, and the _languageId from the context as the other key?

public class SampleDataContext : DbContext
{
    int _languageId;

    public SampleDataContext(int languageId)
    {
        _languageId = languageId;
    }

    public DbSet<LocalizedName> LocalNames { get; set; }
    public DbSet<Product> Products { get; set; }
    public DbSet<Language> Languages { get; set; }
}

public class LocalizedName
{
    [Key, Column(Order = 0)]
    public Guid Key { get; set; }

    [Key, Column(Order = 1)]
    public int LanguageId { get; set; }

    public string Name { get; set; }
}

public class Language
{      
    public int Id { get; set; }
    public string Name{ get; set; }
}

public class Product
{
    public int Id { get; set; }
    public string Sku { get; set; }
    public Guid LocalNameKey { get; set; }
}
  • 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-14T12:28:30+00:00Added an answer on June 14, 2026 at 12:28 pm

    No you can’t. If you try, EF will try to create a table corresponding with the context and probably choke trying.

    You’ll have to use a repository pattern to make sure that queries on any localized entity also incorporate a language id (which would be encapsulated in the repository, not the context).

    As an aside, having FK’s to localized entries for each individual property of an entity can be very demanding performance-wise. See this Q&A for some good tips (not only the accepted answer).

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

Sidebar

Related Questions

Given this code, tableButton = new JButton(new ImageIcon(80F_FG2015.GIF)); how would I get that String
Can anyone explain why this code with the given routes returns the first route?
This portion of code checks if a number given (First element in a list)
So I was given this code in a folder of bits and pieces that
Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
Given this code: List<string> things = new List<string>(); foreach (string thing in things) {
I'm learning about pointers. Given this code: FILE* from = fopen("in.txt", "r"); FILE* to
Given this JavaScript code (which is just a comment referring to a url): //
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:

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.