How to convert LINQ query result to List?

前端 未结 5 1452
花落未央
花落未央 2020-12-06 09:51

I need to convert linq query result to list. I tried the following code:

var qry = from a in obj.tbCourses
                    


        
5条回答
  •  无人及你
    2020-12-06 10:13

    You need to use the select new LINQ keyword to explicitly convert your tbcourseentity into the custom type course. Example of select new:

    var q = from o in db.Orders
            where o.Products.ProductName.StartsWith("Asset") && 
                  o.PaymentApproved == true
            select new { name   = o.Contacts.FirstName + " " +
                                  o.Contacts.LastName, 
                         product = o.Products.ProductName, 
                         version = o.Products.Version + 
                                  (o.Products.SubVersion * 0.1)
                       };
    

    http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx

提交回复
热议问题