0
public class Account
{
    public List<Memo1> Memos { get; set; }
}

public class Memo1
{
    public string Memo { get; set; }
    public DateTime AddDate { get; set; }
    public string UserID { get; set; }
    public List<MemoRefferances1> MemoRefferances { get; set; }
}

public class MemoRefferances1
{
    public string RefferanceName { get; set; }
    public string RefferanceValue { get; set; }
}

I want to select values of RefferanceName and RefferanceValue in MemoRefferances1 class. Please Help me.

2
  • Does this answer your question? Linq: List of lists to a long list Commented Feb 3, 2020 at 6:00
  • What are the properties available in MemoRefferances1 class. Only two which you mentioned in question or others as well, because SelectMany gives you entire object of IEnumerable<MemoRefferances1> class and if you need selective properties from that object then you need Select() as well Commented Feb 3, 2020 at 6:00

3 Answers 3

2

You can use SelectMany to get all the MemoRefferances1 in Account.Memos

var results = someAccount.Memos.SelectMany(x => MemoRefferances);
Sign up to request clarification or add additional context in comments.

Comments

2

You need SelectMany:

Projects each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence.

var allMemoRefferances = account.Memos.SelectMany(x = x.MemoRefferances);

Comments

0

You can use the following code,

Account dummy = GetAccouns(); //Assume GetAccounts fills account data
var result = dummy.Memos.SelectMany(x => x.MemoRefferances).ToList();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.