LINQ to SQL - How to select specific columns and return strongly typed list

前端 未结 3 1205
不思量自难忘°
不思量自难忘° 2020-12-08 02:10

I\'m trying to use LINQ to SQL to select a few specific columns from a table and return the result as a strongly typed list of objects.

For Example:



        
3条回答
  •  余生分开走
    2020-12-08 02:45

    Make a call to the DB searching with myid (Id of the row) and get back specific columns:

    var columns = db.Notifications
                    .Where(x => x.Id == myid)
                    .Select(n => new { n.NotificationTitle, 
                                       n.NotificationDescription, 
                                       n.NotificationOrder });
    

提交回复
热议问题