Using LINQ to Select a Different Type
How can I convert my List object to List<CustomObjects>
Currently am doing as
var db = new DataClasses1DataContext();
var list =
(from t in db.CTRL_DATA_ERROR_DETAILs
select new {t.DATA_ERROR_KEY, t.CTRL_DATA_ERROR_MASTER.CREATION_DATE})
.ToList();
var cus = new List<CustomObjects>();
foreach (var list1 in list)
{
var cs = new CustomObjects
{
MasterColumn = list1.DATA_ERROR_KEY.ToString(),
ChildColumn = list1.CREATION_DATE.ToStrin开发者_运维知识库g()
};
cus.Add(cs);
}
Is there other good way to do this.
You should be able to create the CustomObject list in the initial step like so:
var db = new DataClasses1DataContext();
var cus =
(from t in db.CTRL_DATA_ERROR_DETAILs
select new CustomObjects { MasterColumn = t.DATA_ERROR_KEY.ToString(),
ChildColumn = t.CTRL_DATA_ERROR_MASTER.CREATION_DATE.ToString()})
.ToList();
I haven't compiled the code, but the concept should be right.
精彩评论