Linq Query with multiple joins and multiple conditions -


i using telerik data access perform or mapping.

i trying use linq performing join query not sure how proceed correctly.

the original sql query given by:

'select o.ops_leg_id, o.atd_date, o.dep_airport_act, o.arr_airport_act, o.ata_date,  '+                           'o.fl_log_atd_date, o.fl_log_ata_date, o.fl_log_dep_airport, o.fl_log_arr_airport, '+                           'o.fl_nb, o.designator, o.fl_log_id, o.fl_log_status '+                           'from crew_rot_role cr, ops_leg o, crew_roles r, crew_pairing_cmp cp '+                           'where cr.role_cde = r.role_cde '+                             'and cr.crew_rotation_id = cp.crew_rotation_id '+                             'and cp.ops_leg_id = o.ops_leg_id '+                             'and cr.crew_cde = :crew_cde '+                             'and o.atd_date >= :d_from '+                             'and o.atd_date <= :d_to '+                             //'and r.role_type = 0 '+                           'order o.atd_date 

the corresponding entities have been generated sql tables. trying build equivalent linq query, not seem work:

var results = opsleg in dbcontext.ops_legs                               crewrotationrole in dbcontext.crew_rot_roles                               crewrole in dbcontext.crew_roles                               crewpairingcomponent in dbcontext.crew_pairing_cmps                               crewrotationrole.role_cde == crewrole.role_cde                               && crewrotationrole.crew_rotation_id == crewpairingcomponent.crew_rotation_id                               && crewpairingcomponent.ops_leg_id == opsleg.ops_leg_id                               && crewrotationrole.crew_cde == userid                               select new { opslegid = opsleg.ops_leg_id,                                            designator = opsleg.designator,                                            flightnumber = opsleg.fl_nb                                          }; 

trying previous query, raises exception:

"identifier 'role_cde' not parameter or variable or field of 'flightlogentities.ops_leg'. if 'role_cde' property please add fieldalias or storage attribute or declare field's alias."

not sure how proceed. correct query using linq joins? thanks!

if using orm entity framework, conceptual model mix of classes, provide object centric view of data.

so, using linq on objects , in case need not write queries joins in sql database. conceptual model contain objects having relationships using navigational properties, , access navigational properties can access them property of object.

for e.g if there 2 tables in database, customer & orders. following sql statement return orders customer number 1:

select customers.customername, orders.orderid customers inner join orders on customers.customerid=orders.customerid customers.customerid = 1  

if use ef generate generate conceptual model database, class customer , order , customer class have property of icollection. so, if need same results sql query above, in following way

var customerone = context.customers.where(x => x.customerid == 1); var ordersforcustomerone = customerone.orders; 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -