Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq to SQL DTOs and composite objects
    primarykey
    data
    text
    <p>I am using a similar approach to others in keeping my LINQ objects in my LINQ data provider and returning an IQueryable to allow filtering etc. This works fine for filtering a simple object by it's ID or other property, but I am having a problem with a join table object that is composed of other child objects</p> <pre><code> //CoreDBDataContext db = coreDB; public IQueryable&lt;DTO.Position&gt; GetPositions() { return from p in coreDB.Positions select new DTO.Position { DTO.User = new DTO.User(p.User.id,p.User.username, p.User.firstName,p.User.lastName,p.User.email,p.User.isActive), DTO.Role = new DTO.Role(p.Role.id, p.Role.name, p.Role.isActive), DTO.OrgUnit = new DTO.OrgUnit(p.OrgUnit.id,p.OrgUnit.name,p.OrgUnit.isActive) }; </code></pre> <p>The coreDB.Positions is my Linq Position Object and I am returning a DTO Position which is composed of a User, OrgUnit and Role (the underlying table is a join table with UserID, RoleID, and OrgUnitID)</p> <p>The problem I am having is that when I try to add a filter on the Iqueryable I get a SQL Error saying that there is no translation available for my DTO.User object</p> <pre><code>public static IQueryable&lt;Position&gt; WithUserID(this IQueryable&lt;Position&gt; query, int userID) { return query.Where(p =&gt; p.User.ID == userID); } </code></pre> <p>I am at a complete loss as to how to go about resolving this, as all of my Google results seem to be with people working directly with the generated LINQ objects</p> <p>Any thought as to how to make this work, or am I doing something completely wrong here?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload