what possible workarounds are there for "only parameterless constructors are support in Linq to Enti
Posted
by Ralph Shillington
on Stack Overflow
See other posts from Stack Overflow
or by Ralph Shillington
Published on 2010-06-13T01:53:13Z
Indexed on
2010/06/13
2:02 UTC
Read the original article
Hit count: 428
entity-framework
|linq-to-entities
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.
© Stack Overflow or respective owner