none
entity frame work social network complex query. how to implement? RRS feed

  • Question

  • hello,

    I am working on ASP.NET MVC 3 social network.. i am trying to implement like facebook and google plus features..

    one of the feature that i feel hard to implement is google plus' circles (facebook lists)..

    let's say that the user asked for the "family" list stream..

    then i want to get the 'family' list (listId = 2)

    and get the persons i listed in this list

    and foreach person i want to get his lists which he put me in..

    and foreach of these lists.. i want to get the entities taged with list..

    for each entity i want the last 2 comments and the author

                var list2 = db.Lists
                                .Where(l =>
                                    l.Author.LogonName == User.Identity.Name &&
                                    l.ListId == 2
                                )
                                .Select(l =>
                                    l.InListPersons
                                        .Select(ip =>
                                            ip.Lists
                                                .Where(li =>
                                                    li.InListPersons
                                                          .Where(ilp => ilp
                                                              .LogonName == "Wisam"
                                                          )
                                                          .Count() > 0
                                                )
                                                .Where(li =>
                                                    li.Entities.Count() > 0
                                                )
                                                .Select(
                                                    li =>
                                                        li.Entities
                                                            .OrderByDescending(e => e.Time)
                                                            .Take(25)
                                                            .Select(e => e
                                                                .Comments
                                                                .OrderByDescending(c => c.Time)
                                                                .Take(2)
                                                                    .Select(c => c
                                                                        .Author
                                                                    )
                                                                )
                                                )
                                        )
                                )
                                .ToList();

    i have just created this query, but it dosen't do what i want it, return IEnumerable instead of list object..

    what i want is a source, tutorial for very complex entity frame work querys like the one i asked for..

    or if you can give me hand implemeting the required query..

    thank you...


    http://www.facebook.com/wisam.mways

    Friday, September 7, 2012 11:46 PM

Answers

  • Hi Wisam,

    Welcome to the MSDN forum.

    I have not the data resource, so it is hard to reproduce your problem on my side. I recommend you try to use ToList() method separately. It means one line for linq, another line for ToList(). For Example:

    var query2 = db.Lists

                                 .Where(l =>

                                     l.Author.LogonName == User.Identity.Name &&

                                     l.ListId == 2

                                 )

                                 .Select(…

                           

                                         );

    var list2=query2.ToList();

    Then test if the list2 is the List type. Also I recommend you try to check if the result of query2 is want you want. If the results is wrong, please try to write the linq query separately to check if it returns correct results separately.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Tuesday, October 9, 2012 8:23 AM
    Monday, September 10, 2012 3:16 AM

All replies

  • Hi Wisam,

    Welcome to the MSDN forum.

    I have not the data resource, so it is hard to reproduce your problem on my side. I recommend you try to use ToList() method separately. It means one line for linq, another line for ToList(). For Example:

    var query2 = db.Lists

                                 .Where(l =>

                                     l.Author.LogonName == User.Identity.Name &&

                                     l.ListId == 2

                                 )

                                 .Select(…

                           

                                         );

    var list2=query2.ToList();

    Then test if the list2 is the List type. Also I recommend you try to check if the result of query2 is want you want. If the results is wrong, please try to write the linq query separately to check if it returns correct results separately.

    Good day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Alexander Sun Tuesday, October 9, 2012 8:23 AM
    Monday, September 10, 2012 3:16 AM
  • Hi Wisam-Mo,

    Any updates on this thread? Please feel free to let me know.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, September 19, 2012 7:08 AM