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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:07:16+00:00 2026-05-18T22:07:16+00:00

I used the ADO.NET C# POCO Entity Generator Visual Studio add-in to generate POCO

  • 0

I used the ADO.NET C# POCO Entity Generator Visual Studio add-in to generate POCO classes for my entities.

When I try to use the class in a Linq to Entities query such as the one below:

var q = from w in entities.Widgets
        select new Widget
        {
            Id = w.Id,
            WidgetName = w.WidgetName,
            WidgetDescription = w.WidgetDescription
        };


return q.ToList();

I get the following exception:

“The entity or complex type MyNamespace.Widget’ cannot be constructed in a LINQ to Entities query”.

The only way around this is to use an anonymous type and then another LINQ query:

var q = from w in entities.Widgets
        select new
        {
            Id = w.Id,
            WidgetName = w.WidgetName,
            WidgetDescription = w.WidgetDescription
        };

var r = from e in q.AsEnumerable()
        select new Widget
        {
            Id = e.Id,
            WidgetName = e.WidgetName,
            WidgetDescription = e.WidgetDescription
        };

return r.ToList();

This works but is pretty redundant. I understand why I’m getting the exception, but is there a more elegant way around this?

The fact that the POCO classes are generated by the ADO.NET C# POCO Entity Generator doesn’t seem related to the issue; I tried using my own POCO classes and saw the same exception.

Many thanks.

EDIT:
Added link to walkthrough for using the ADO.NET C# POCO Entity Generator Visual Studio add-in – http://blogs.msdn.com/b/adonet/archive/2010/01/25/walkthrough-poco-template-for-the-entity-framework.aspx

  • 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-18T22:07:17+00:00Added an answer on May 18, 2026 at 10:07 pm

    I’m guessing MyNamespace.Widget is a custom class – and not part of the EDM?

    If so, you can’t project a LINQ-Entities query into a custom type. Doesn’t matter if your using POCO’s or not.

    You’ve got the right idea projecting to an anonymous type.

    You can shape the query on the client once you have materialized the query on the server:

    var widgets = entities
                   .Widgets
                   .ToList() // materialize query
                   .Select(x => new Widget
                           {
                              Id = w.Id,
                              WidgetName = w.WidgetName,
                              WidgetDescription = w.WidgetDescription
                           }
                   ).ToList();
    

    Which is a bit nicer than your workaround.

    But this begs the question – why aren’t you returning the “Widget” type on the EDM in the first place?

    The whole point of POCO’s is so you can seperate the persistence-logic into simple classes. So i’m not sure why your projecting from a simple type (POCO), to another (seemingly identical) simple type. Are you mapping your POCO’s to DTO’s for N-Tier transport?

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

Sidebar

Related Questions

All, I have successfully used ADO.NET to make use of asynchronous SQL queries similar
In my application I used Entity Framework generated from a db with ado.net dbcontext
When I used to use ADO.NET, I used to create TableAdapters which were populated
I am trying to use ADO.Net Codefirst feature of latest Entity Framework 4.0. As
I am using ADO.NET Mocking Context Generator plugin for my Entity Framework model. I
Which orm you would recommend for a beginner moving from ado.net?... Thus far used
I used the xsd.exe tool to generate a class based on my xml schema.
I have my asp.net mvc 3 application with entity framework and i used the
When it comes to Ado.net connection strings, I have used Initial Catalog attributes at
C# ADO.Net TableAdapter objects do not implement an interface or a base class (other

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.