This query works great:
var pageObject = (from op in db.ObjectPermissions join pg in db.Pages on op.ObjectPermissionName equals page.PageName where pg.PageID == page.PageID select op) .SingleOrDefault();
I get a new type with my ‘op’ fields. Now I want to retrieve my ‘pg’ fields as well, but
select op, pg).SingleOrDefault();
doesn’t work.
How can I select everything from both tables so that they appear in my new pageObject type?
You can use anonymous types for this, i.e.:
This will make pageObject into an IEnumerable of an anonymous type so AFAIK you won’t be able to pass it around to other methods, however if you’re simply obtaining data to play with in the method you’re currently in it’s perfectly fine. You can also name properties in your anonymous type, i.e.:-
This will enable you to say:-
For example 🙂