AlexW
AlexW

Reputation: 2589

specified type member FullName is not supported in LINQ to Entities

Im getting the error"specified type member FullName is not supported in LINQ to Entities" when using select d.FullName, is it because it is not part of the table?

How do I fix this?

Thanks

USER CLASS
public partial class tblUser
{
    public tblUser()
    {
        this.Equipment = new HashSet<tblEquipment>();
    }

    public int ID { get; set; }
    public string Forename { get; set; }
    public string Surname { get; set; }

    public string FullName { get { return Forename + " " + Surname; } }

QUERY WITH ERROR

string[] arrUsers = (from d in db.tblUsers select d.FullName).ToArray();

Upvotes: 1

Views: 1068

Answers (2)

It&#39;sNotALie.
It&#39;sNotALie.

Reputation: 22794

You'll have to select it manually:

string[] arrUsers = (from d in db.tblUsers select (d.Forename ?? "") + " " + (d.Surname ?? "")).ToArray();

Upvotes: 3

Rapha&#235;l Althaus
Rapha&#235;l Althaus

Reputation: 60493

because it doesn't exist in your db, so linq2entities can't generate proper sql

so

Solution1

concatenate in your query, using a coalesce operator (if you don't and one part is NULL, all will be null).

select d.ForeName ?? string.Empty + " " + d.Surname ?? string.Empty

Solution2

  select d.Forename, d.Surname

and you will be able to use FullName when you'll have enumerated the Queryable

Solution3

Use a computed column

Upvotes: 2

Related Questions