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

  • Home
  • SEARCH
  • 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 3331924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:38:03+00:00 2026-05-17T23:38:03+00:00

I’ve this simple Entities from DB tables But i want my POCO classes to

  • 0

I’ve this simple Entities from DB tables
alt text

But i want my POCO classes to be just two classes:

public class Country
{
    public string ID { get; set; }

    public string Name { get; set; }

    public string LocalName { get; set; } // this localized

    public string Region { get; set; }

    public IEnumerable<City> Cities { get; set; }
}

public class City
{
    public int ID { get; set; }

    public string CountryID { get; set; }

    public string Name { get; set; } //this localized

    public double? Longitude { get; set; }

    public double? Latitude { get; set; }
}

Then i want Localized properties “LocalName for the Country and Name for the City” to be filled by my context.

So how to map this Entities to POCO Classes?

And is there better way to do that?

Or i should make manual converting from Entities to my Model and add one more tier ?

Please help me to take decision .

.

: Additional information:

I made my ObjectContext to deal with my POCO but when i try to fill my Additional property “LocalName” in repository i get this error:

The entity or complex type 'Site.Country'  cannot be constructed

in a LINQ to Entities query.

and this is the method in my Repository:

       public IQueryable<Country> GetCountries()
       {
           return from country in context.Countries
                  join countryCul in context.CountriesCultures 
                  on country.Code equals countryCul.CountryID
                  where countryCul.LangID == "en"
                  select new Country
                             {
                                 Code = country.Code,
                                 LocalName = countryCul.LocalName,
                                 Name = country.Name,
                                 Region = country.Region,
                             };
       }

I don’t know how to fill “LocalName” property within linq statement

  • 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-17T23:38:04+00:00Added an answer on May 17, 2026 at 11:38 pm

    if you want a solution with ViewModel class, you can pick up these:

    For wrapping City with it’s selected LocalLanguage

    public class CityLocolized
    {
        public City City { get; set; }
        public String LocalName { get; set; }
    }
    

    Here, we chose the either default so with if else no join, else chose from CityCulture table

    string lang = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
    List<CityLocolized> citiesLocalized = null;
    if (lang == "en") // which is default in db
    {
        citiesLocalized = (from c in fke.Cities
                        select new CityLocolized
                        {
                            City = c,
                            LocalName = c.Name
                        }
                        ).ToList();
    }
    else // for other languages 
    {
        citiesLocalized = (from c in fke.Cities
                        join cc in fke.CityCultures
                        on c.Id equals cc.CityId
                        where cc.LangId == lang
                        select new CityLocolized
                        {
                            City = c,
                            LocalName = cc.LocalName
                        }).ToList();
    
    }
    

    and this one for passing View:

       ViewData["CitiesLocolized"] = new SelectList(citiesLocalized, "City.Id", "LocalName");
    

    finally at view:

      <%:Html.DropDownListFor(model => model.CityId,  ViewData["CitiesLocolized"] as SelectList)%>
    

    i think this is it.

    moguzalp

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.