I’m having a problem with LINQ
var operations = (from c in dCAPPEntities.CIC_OPERAZIONI
where c.CD_CIC_PRODUZIONE == 15835 && !(from s in dCAPPEntities.CIC_SEQUENCE where s.CD_CIC_PRODUZIONE==15835 select s.CD_CIC_OPERAZIONE).Contains(c.CD_CIC_OPERAZIONI) select new { c }).GroupBy(i=>i.c.CD_CIC_OPERAZIONI, i=> new Alternative1{ State=0, Iden=i.c.Iden});
when I execute this query I get the following error:
The specified type member ‘Iden’ is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
if I write Iden=”” in the query it works, so I have no idea why I got the error.
I also add the code of some classes I used:
public interface IAlternative
{
string Iden { get; }
int State { get; set; }
}
partial class that extends the table
public partial class CIC_OPERAZIONI : IAlternative
{
public string Iden
{
get
{
return AFCDOPER + "\r" + AFDSOPER;
}
}
private int _state = 0;
public int State
{
get { return _state; }
set
{
_state = value;
}
}
}
and the last class i think can be useful to understand the problem
public class Alternative1 : INotifyPropertyChanged, IAlternative
{
public event PropertyChangedEventHandler PropertyChanged;
#region IAlternative Members
public string Iden { get; set; }
public int State { get; set; }
cis aCIC_OPERAZIONI.CIC_OPERAZIONI.Idenis not an entity member or navigation property, it’s a computed property with a value that depends on other properties. EF doesn’t support that: your query doesn’t actually end up creatingCIC_OPERAZIONIobjects, so there is no way to haveCIC_OPERAZIONImember functions or properties get called. Depending on the definition of the other properties, it may or may not work if you expand it inline:If it doesn’t work, it’s probably because
AFCDOPERorAFDSOPERisn’t an entity member either, and you need to do the same with those other properties.