locked
Joining in linq query with Microsoft Dynamics CRM RRS feed

  • Question

  • i am working on a project which uses Microsoft dynamics crm, i am fetching data using Linq from XrmServiceContext, i have two entities like this=>

    booking=>

    bookingId [pk]
    createdBy (user)
    booking_name


    shareInfo=>

    shareInfoId [pk]
    bookingId
    sharedWith (user)


    i have to select all booking created by "user1" and shared to "user1" in single query,

    i tried following but did not work

    var bookings = (from booking in SvcContext.bookingSet
                        join shared in SvcContext.SharedInfoSet on booking.bookingId equals shared.bookingId.Id
                        where booking.createdBy.Id == new Guid(userId) || shared.new_BookingSharedWith.Id== new Guid(accountId)
                        select booking).ToList();

    Please help..

    Friday, November 7, 2014 12:36 PM

All replies

  • Below is the code, to do soo...
    Try it.

                Guid User1 = new Guid("0C90C49C-B366-E111-9DCF-080027402BF9");
    
                var FilteredBookingList = (from booking in xrm.new_bookingSet.Where(c => c.CreatedBy.Id.Equals(User1)).ToList()
                                           join shareInfo in xrm.new_shareinfoSet.Where(b => b.new_sharedTo.Id.Equals(User1)).ToList()
                                           on booking.Id equals shareInfo.new_Booking.Id
                                           select booking).ToList();



    Friday, November 7, 2014 3:18 PM
  • Hi,

    Can you add the bold part below

    var bookings = (from booking in SvcContext.bookingSet
                        join shared in SvcContext.SharedInfoSet on booking.bookingId.Value equals shared.bookingId.Id
                        where booking.createdBy.Id == new Guid(userId) || shared.new_BookingSharedWith.Id== new                         Guid(accountId)
                        select booking).ToList();


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog


    Friday, November 7, 2014 3:27 PM