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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:33:24+00:00 2026-05-15T08:33:24+00:00

In my query I need to return instances of a class that doesn’t have

  • 0

In my query I need to return instances of a class that doesn’t have a default constructor (specifically this is in a custom Membership provider, and MembershipUser is the culprit)

var users = from l in context.Logins
    select new MembershipUser(
        Name,
        l.Username, // username
        l.Id, // provider key
        l.MailTo,
        l.PasswordQuestion,
        l.Notes.FirstOrDefault().NoteText,
        l.IsApproved,
        l.IsLockedOut,
        l.CreatedOn,
        l.LastLoginOn.HasValue ? l.LastLoginOn.Value : DateTime.MinValue,
        l.LastActivityOn.HasValue ? l.LastActivityOn.Value : DateTime.MinValue,
        DateTime.MinValue,
        l.LastLockedOutOn.HasValue ? l.LastLockedOutOn.Value : DateTime.MinValue
    );

is syntacitally correct, but results in a runtime error as Only parameterless constructors and initializers are supported in LINQ to Entities.

Update: as a workaround I’m now bringing the selection into a List (which resolves the runs the query expression) then I can select the new MembershipUser from that list.

var users = (from l in context.Logins
    select new { login = l }).ToList().Select(u => new MembershipUser (
Name,
u.login.Username, // username
u.login.Id, // provider key
u.email.MailTo,
u.login.PasswordQuestion,
u.login.Notes.FirstOrDefault().NoteText,
u.login.IsApproved,
u.login.IsLockedOut,
u.login.CreatedOn,
u.login.LastLoginOn.HasValue ? u.login.LastLoginOn.Value : DateTime.MinValue,
u.login.LastActivityOn.HasValue ? u.login.LastActivityOn.Value : DateTime.MinValue,
DateTime.MinValue,
u.login.LastLockedOutOn.HasValue ? u.login.LastLockedOutOn.Value : DateTime.MinValue
    );
  • 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-15T08:33:24+00:00Added an answer on May 15, 2026 at 8:33 am

    I think the problem is that you need to escape from LINQ to Entities and get to LINQ to Objects, which allows arbitrary method calls. The AsEnumerable extension method does this for you.
    How about this:

    var users = from l in context.Logins.AsEnumerable() 
        select new MembershipUser( 
            Name, 
            l.Username, // username 
            l.Id, // provider key 
            l.MailTo, 
            l.PasswordQuestion, 
            l.Notes.FirstOrDefault().NoteText, 
            l.IsApproved, 
            l.IsLockedOut, 
            l.CreatedOn, 
            l.LastLoginOn ?? DateTime.MinValue, 
            l.LastActivityOn ?? DateTime.MinValue, 
            DateTime.MinValue, 
            l.LastLockedOutOn ?? DateTime.MinValue 
        ); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a query that will return a table where each column is the
I need to setup a SELECT query that will return rows based on matching
how set distinct to this query return _dataContext.ProjectPictures.Include(Projects).Include(ProjectPictureTypes).Where(p => p.ProjectPictureTypes.Id == 1).ToList(); i need
In the projects I worked on I have classes that query/update database, like this
I have a class that builds a url with query string parameters and so
I need to create a xpath query that will return everything listed under availabilty
I have a MenuObject class that represents a websites Top Menu. This object has
I am having some trouble building the query I need to return the AccountID
Why the two query below return duplicate member_id and not the third? I need
I need to write a query that returns all object less that or equal

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.