我有一個方法應該返回一個Rpt_IncidentWithConfirm對象,但我不知道如何輕鬆地將其轉換爲一個。我知道它是如何做的唯一方法就是做到我在下面做的是非常低效的。匿名類型轉換爲名義類型
public Rpt_IncidentWithConfirm GetIncident(string IncidentID)
{
db = new IncidentsDataContext();
var incident = (from i in db.Rpt_IncidentWithConfirms
join d in db.DropDowns on i.incidentType equals d.value
where i.incidentID == Convert.ToInt32(IncidentID)
select new
{
i, d.text
}).SingleOrDefault();
Rpt_IncidentWithConfirm r = new Rpt_IncidentWithConfirm();
// I didn't want to have to type all this here because I have too many fields to map.
r.bhaIncident = incident.i.bhaIncident;
r.bitType = incident.i.bitType;
r.Bottom_Connection = incident.i.Bottom_Connection;
// And so on.
return r;
}
匿名類型如下命名類型爲強,他們只是沒有一個名稱而已 –
@Rune良好的出發點。它通常是*名義*與匿名類型。 – dlev
什麼「非常低效」? –