1

I try to create a join query in Linq. I want to join a table more than one field with same

table. Please see my code below.

var roles = (from ords in _orderRepository.Table 
                         join customers in _customerRepository.Table on ords.CustomerId equals customers.Id
                         join ordprvrnts in _orderProductVariantRepository.Table on ords.Id equals ordprvrnts.OrderId
                         join prdvrnts in _productVariantRepository .Table on ordprvrnts.ProductVariantId equals prdvrnts.Id
                         **join cstevntrle in _customerEventRoleRepository.Table on 
                             new{  customers.Id equals cstevntrle.CustomerId } && 
                             new { cstevntrle.EventId == model.Event}**
                         orderby customers.Email ascending
                         select new CustomerEventRolesModel
                         {

                             Customer = customers.Email,
                             CUstomerId =customers.Id

                         });

I try to filter customerEventRoleRepository.Table with CustomerId and EventId

how can i do this in this join query.

Please Help.

4

1 に答える 1

3

you have boolean comparisons in your anonymous type definitions...

change your on clause to the following:

join cstevntrle in _customerEventRoleRepository.Table on 
    new { CustomerId = customers.Id, EventId = model.Event.EventId } equals 
    new { CustomerId = cstevntrle.CustomerId, EventId = cstevntrle.EventId }

I don't see "model" defined anywhere, so I'm not sure this is going to work, but it should be enough to demonstrate how joins based on multiple fields works - each anonymous class contains the fields from one "side" of the join.

于 2013-03-27T06:54:03.313 に答える