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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:59:55+00:00 2026-06-12T23:59:55+00:00

I’ve been noticing when I pull things out of the my MSSQL db using

  • 0

I’ve been noticing when I pull things out of the my MSSQL db using LINQ-to-SQL using something simple like:

    public IEnumerable<Contact> GetAll()
    {
        var Contacts = from c in _context.Contacts
                      select new Models.Contact
                      {
                          ContactID = c.ContactID,
                          FirstName = c.FirstName,
                          LastName = c.LastName,
                          Email = c.Email,
                          Phone = c.Phone,
                          Address1 = c.Address1,
                          Address2 = c.Address2,
                          City = c.City,
                          State = c.State,
                          Zip = c.Zip,
                          HighImportance = (bool)c.HighImportance,
                          PrimaryContact = (bool)c.PrimaryContact,
                          OfficeLocation = c.OfficeLocation
                      };
        return Contacts;
    }

I have a complex object (foreign key reference) to an OfficeLocations table which I would like to populate. If I do something like:

_context.OfficeLocations.SingleOrDefault(ol => ol.OfficeLocationID == c.OfficeLocationID);

Then this returns the type which is generated by my DBML. Up to now I’ve been using something like:

OfficeLocation = new OfficeLocation
            {
                OfficeLocationID = c.OfficeLocationID,
                Name = c.OfficeLocation.Name,
                Phone = c.OfficeLocation.Phone
            }

But I feel like there should be a much better way to do it, maybe by using extension methods on my DBML data objects or something?

Any thoughts would be greatly appreciated.

Thanks!

  • 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-12T23:59:56+00:00Added an answer on June 12, 2026 at 11:59 pm

    You should checkout AutoMapper. It’s a very good library that would help you setup mapping between objects in your application. For example, you might have domain entities and a layer of DTO’s; then you can use AutoMapper to map from your entities to the corresponding DTO’s, which I assume is what you’re looking to do.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
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 am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a

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.