Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public enum EnSituation
    {
        Sit1 = 1,
        Sit2,

public virtual Person Person (get; set;)
public EnSituation Situation
        {
            get
            {
                if (this.Sit1)
                    return EnSituation.Sit1;

                if (this.Sit2)
                {
                    if (this.Sit2)
                        return EnSituation.Sit2;
                    else
                        return EnSituation.Sit;
                }

            }
        }
		
		
var dataList = this.GetByFilters(filters)
	.Select(_ => new DataItem
	{
		Id = _.Id.ToString(),
		Name = _.Person.Name + " (" + _.Situation.ToString() + ")",
	}); 
	return await this.rep.ToListAsync(dataList);



What I have tried:

when i run this code i recive the message error: Common.Domain.CustomExceptions.CustomValidationException: 'Exception: The specified type member 'Stituation' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.'
Can anyone help me please?
Posted
Updated 23-Apr-20 6:32am

1 solution

C# code inside a property getter cannot be translated to a SQL query. You cannot use the Situation property in a LINQ query that's executed against the database.

Try:
C#
var rawList = await this.GetByFilters(filters).ToListAsync();

var dataList = rawList
    .Select(_ => new DataItem
    {
        Id = _.Id.ToString(),
        Name = _.Person.Name + " (" + _.Situation.ToString() + ")",
    })
    .ToList();
Or:
C#
var dataList = this.GetByFilters(filters)
    .AsEnumerable()
    .Select(_ => new DataItem
    {
        Id = _.Id.ToString(),
        Name = _.Person.Name + " (" + _.Situation.ToString() + ")",
    })
    .ToList();
 
Share this answer
 
Comments
Fernando_Costa 23-Apr-20 13:22pm    
when i had put "return this.rep.ToListAsync(dataList), now is just "return dataList"?
Richard Deeming 23-Apr-20 13:23pm    
Yes.
Fernando_Costa 23-Apr-20 13:30pm    
so the second anwser works!!! tank you very much
Maciej Los 23-Apr-20 14:53pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900