LINQ Join and GroupJoin -


i have list of objects, objects may or may not have contact info:

            // join contact         query = query.join(         (new contactrepository(this.db)).list().where(x => x.ismaincontact),         x => new { x.listitem.contentobject.loginid },         y => new { y.loginid },         (x, y) => new listitemextended<listitemfirm>         {             city = y.city,             state = y.state,             country = y.country         }); 

this inner join on 'loginid'. need outter join if contact info not exists given loginid empty. please help

thanks

you should execute outer join manually:

            var contacts = (new contactrepository(this.db)).list();             query.select(item =>              {                 var foundcontact = contacts.firstordefault(contact => contact.id == item.id);                 return  new listitemextended<listitemfirm>()                     {                         id = item.id,                         city = foundcontact != null ? foundcontact.city : null,                         state = foundcontact != null ? foundcontact.state : null,                         country = foundcontact != null ? foundcontact.country : null,                     };             }) 

but remember if contact item struct - checking null isn't proper way. use any() operator instead of firstordefault().


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -