Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query using linq statements?

Tags:

c#

linq

I have two objects

List<Report> 
List<Newsletter>

I need certain properties like

Id
Date
Status
text

from the two lists. Is there a way to merge these list and query it using linq statement to return the specific properties as a separate list? Please help.

Structure of the object is as follows:

Report
{
    int id,
    datetime reportDate, 
    enum Status,
    string text
};

Newsletter
{
    int id, 
    datetime newsletterDate,
    string Status,
    string text
};
like image 950
NewBie Avatar asked Dec 01 '25 05:12

NewBie


1 Answers

var items = 
      reportList.Select(x =>  new { x.Id, x.Date, x.Status, x.text })
      .Concat(
        newsList.Select(x =>  new { x.Id, x.Date, x.Status, x.text }) );

Update, to equalize the Status properties:

var items = 
      reportList.Select(x =>  new { x.Id, x.Date, Status = x.Status.ToString(), x.text })
      .Concat(
        newsList.Select(x =>  new { x.Id, x.Date, Status, x.text }) );
like image 86
Henk Holterman Avatar answered Dec 03 '25 18:12

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!