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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:35:48+00:00 2026-05-16T15:35:48+00:00

I’m trying to solve a problem similar to the one described here Initializing strongly

  • 0

I’m trying to solve a problem similar to the one described here

Initializing strongly typed objects in LINQ to Entities

only from totally the opposite direction. I have a number of functions in my repository, all of which return identically shaped data. The issue is my projection code:

select new pocoClass
 {
   // complex projection that is several pages long includes grabbing a graph of data
 }

at the moment it exists for each query in the repository. I’d tried moving it into an object initializer, but that gives me the dreaded “Only parameterless constructors and initializers are supported in LINQ to Entities.” issue.

I did try splitting into two queries

var candidates = (from thing in _entities.whatever
  where (complex.stuff==true)
  select thing);

var final = (from thing in candidates.AsEnumerable()
  let x = thing.ITEMS.Where(blah=>blah.blah==param)
  let y = x.OTHERITEMS.FirstOrDefault()
  select new pocoClass(thing,x,y);

but here final is always null and the code in new pocoClass is never called. I’ve included the let x & y in the above because these always vary between each use of the projection.

So, do I have to go back to multiple copies of my projection or is there another way out of this ?

  • 1 1 Answer
  • 1 View
  • 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-16T15:35:49+00:00Added an answer on May 16, 2026 at 3:35 pm

    I’m not sure it this is usable for you, but what I often do is create projection methods that take an IQueryable and return an IQueryable to translate from a domain object to a DTO. They look much like this:

    public static IQueryable<CustomerDTO> ToCustomerDTO(
        IQueryable<Customer> customers)
    {
        return
            from customer in customers
            select new CustomerDTO()
            {
               ...
            };
    }
    

    This allows me to have this projection in a single place. From several places in my business layer I call such a method.

    There are a few things to note, though:

    • Make sure these projection methods don’t contain any business logic. Having any use case specific filters would be bad.
    • Sometimes you have a DTO that contains a complex object graph that you want efficiently pull from the database in a single query. With a bit of creativity this is very often possible, but not when returning an IQueryable. In that case I return an array of DTOs.
    • I place those projection methods as static methods inside the DTO class. While this isn’t a very clean design, it found out it makes the code very maintainable.

    I hope this helps.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.