Im using EF 6 and I need a LINQ query to fetch all the data to my ViewModel. Every Event has a status (one to one) There are not FK in tables
I want do display something like that:
EventID EventStatusID Name EventDate EventDesc
99 1 Allowed 2000-1-1 Music festival
ViewModel class:
public class EventVM : Event
{
public EventStatus EStatus { get; set; }
}
Event class:
[Serializable]
public class Event
{
public int EventID { get; set; }
public int EventStatusID { get; set; }
public string EventNumber { get; set; }
public DateTime EventDate { get; set; }
public string EventDesc { get; set; }
}
Event status class:
[Serializable]
public class EventStatus
{
public int EventStatusID { get; set; }
public string Name{ get; set; }
public string Desc{ get; set; }
}
Event table:
dbo.Event
Column name Type Allow nulls
PK Eventid int no
Eventstatusid int no
Eventnumber nvarchar no
Eventdate date no
Eventdesc nvarchar no
EventStatus table:
dbo.EventStatus
Column name Type Allow nulls
PK Eventstatusid int no
Desc nvarchar no
Name nvarchar no
I stucked in this moment :
var viewModel =
(from ev in db.Events
join evs in db.EventStatus on ev.EventStatusID equals evs.EventStatusID
where ev.EventStatusID == id
select new EventVM
{
EventID = ev.EventID
}).First();
with error:
System.NotSupportedException: 'The entity or complex type 'ModelEvent.EntityFramework.Concrete.EventVM' cannot be constructed in a LINQ to Entities query.'
I cant change View Model, i have to use this one