when inner join in linq how can i select same column without using model class
when inner join in linq how can i select same column without using model class
Actually ,I want to extract generic data from EF table without using models but unfortunately two columns with same name from different database crashed...
var query = (from jbct in entities.Table1.AsEnumerable()
join p in entities.Table2.AsEnumerable() on jbct.perid equals p.id
select new
jbct.id,
p.id
).ToList();
2 Answers
2
try use a dynamic name
var query = (from jbct in entities.Table1.AsEnumerable()
join p in entities.Table2.AsEnumerable() on jbct.perid equals p.id
select new
Id1 = jbct.id,
Id2 = p.id
).ToList();
okay thanks. I'll also try this. I am able to return dynamic json results in my API without creating specific Models.I used genric collection class . IEnumerable<Dictionary<string, object>>.
– Zuly
Sep 14 '18 at 7:35
@Zuly you can create a dynamic object like this
– tdayi
Sep 14 '18 at 8:03
Now I've found now my solution to usie dictionary class
var query = (from jbct in entities.Table1.AsEnumerable() join p in entities.Table2.AsEnumerable() on jbct.perid equals p.id select new Dictionary<String, Object>
"jbct_id", jbct.id,
"p_id", p.id
).ToList();
Thanks
Still no idea what you're up to. I do know that because of the
AsEnumerable()
calls this is horribly inefficient code.– Gert Arnold
Sep 14 '18 at 7:15
AsEnumerable()
Should I use " IQueryable<Dictionary<string, Object>>" .. instead of AsEnumerable()..
– Zuly
Sep 14 '18 at 7:36
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Frankly, I have no idea what you're asking.
– Gert Arnold
Sep 14 '18 at 7:13