I have this class:
public class Detail
{
public Detail() { }
public Detail(Guid Id, DateTime InstanceDate, string Name)
{
CId = Id;
StateInstanceDate = InstanceDate;
StateName = Name;
}
public Guid CId { get; set; }
public DateTime StateInstanceDate { get; set; }
public string StateName { get; set; }
}
and this how I am trying to access data using LINQ:
public List<Detail> Getinfo()
{
CaseContext cs = new CaseContext();
var query = (from p in cs.table1
join q in cs.table2
on p.StateKey equals q.StateKey
select new Detail
{
p.CId,
p.InstanceDate,
q.StateName
}).ToList<Detail>();
cs.Dispose();
return query;
}
But I am getting this error,
Cannot initialize type 'Detail' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
Any help ?
You have to either assign the properties correctly or use the constructor:
select new Detail( p.CId, p.InstanceDate, q.StateName)
Or
select new Detail
{
CId = p.CId,
StateInstanceDate = p.InstanceDate,
StateName = q.StateName
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With