How to create list of items from another list

DudeThatCodes

How can I create a list from items in another list?

    List<Post> postList = db.Posts.Where(u => u.PostId == postId).ToList();
    List<PostView> viewList = db.PostViews.Where(u => u.PostId **** is equal to PostId within postList**** );

I used the ****'s to show where my understanding falls apart.

Gavin

You can select the Id's from the other list, then see if that list contains your current Id. Although, I would generate the list of Id's first. Assuming your Id's are of type int:

List<Post> postList = db.Posts.Where(u => u.PostId == postId).ToList();
List<int> postIds = postList.Select(u => u.PostId).ToList();
List<PostView> viewList = db.PostViews.Where(u => postIds.Contains(u.PostId)).ToList();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to remove items from a list that contains words found in items in another list

From Dev

Checking if List contains all items from another list

From Dev

How to add items into a ListView from a List of another class

From Dev

How to unpack items from a List?

From Dev

How to copy only new items from one list to another

From Dev

Create a list with items from another list at indices specified in a third list

From Dev

How to filter one list of items from another list of items?

From Dev

Copy list of items to another list

From Dev

Remove items from a List which are in another List by a specific property?

From Dev

Excluding items from a list that exist in another list

From Dev

How to create a List<int> basead on two properties from another list?

From Dev

How to create a list of items from another list based on if the items are the key of an object? (Lodash preferred)

From Dev

How does haskell create a new list from another list?

From Dev

Create session from drop down list items

From Dev

How to transfer items of one static list to another

From Dev

How to remove items from a list that contains words found in items in another list

From Dev

How to unpack items from a List?

From Dev

Create list from list items

From Dev

Remove list of items from another file in bash

From Dev

In Excel how do I create a condensed list from another array?

From Dev

How to create a new list with items from an old list?

From Dev

How to move Items from one list to the another list in python?

From Dev

Create a list from another list with R

From Dev

How does haskell create a new list from another list?

From Dev

find lists that start with items from another list

From Dev

java - create a list from subproperties of another list

From Dev

How to create a list from another list according to a function?

From Dev

Create a list name after another list items in a for loop

From Dev

Create dataframe columns from list with items with Python

Related Related

  1. 1

    How to remove items from a list that contains words found in items in another list

  2. 2

    Checking if List contains all items from another list

  3. 3

    How to add items into a ListView from a List of another class

  4. 4

    How to unpack items from a List?

  5. 5

    How to copy only new items from one list to another

  6. 6

    Create a list with items from another list at indices specified in a third list

  7. 7

    How to filter one list of items from another list of items?

  8. 8

    Copy list of items to another list

  9. 9

    Remove items from a List which are in another List by a specific property?

  10. 10

    Excluding items from a list that exist in another list

  11. 11

    How to create a List<int> basead on two properties from another list?

  12. 12

    How to create a list of items from another list based on if the items are the key of an object? (Lodash preferred)

  13. 13

    How does haskell create a new list from another list?

  14. 14

    Create session from drop down list items

  15. 15

    How to transfer items of one static list to another

  16. 16

    How to remove items from a list that contains words found in items in another list

  17. 17

    How to unpack items from a List?

  18. 18

    Create list from list items

  19. 19

    Remove list of items from another file in bash

  20. 20

    In Excel how do I create a condensed list from another array?

  21. 21

    How to create a new list with items from an old list?

  22. 22

    How to move Items from one list to the another list in python?

  23. 23

    Create a list from another list with R

  24. 24

    How does haskell create a new list from another list?

  25. 25

    find lists that start with items from another list

  26. 26

    java - create a list from subproperties of another list

  27. 27

    How to create a list from another list according to a function?

  28. 28

    Create a list name after another list items in a for loop

  29. 29

    Create dataframe columns from list with items with Python

HotTag

Archive