Link to home
Start Free TrialLog in
Avatar of SniperX1
SniperX1Flag for United Kingdom of Great Britain and Northern Ireland

asked on

LinqToSQL, Repository, Asscociations

I have 2 tables in my database

JobTab has fields jobid int, jobloggedbyid int, jobstate int
JobUser has fields userid int, username, userisactive bit

JobTab jobloggedbyid is a foreign key to userid on on jobusers.

using lingtosql i have added both tables to the dbml, and created the association for the foreign key.

I have IRepository interface with method
Get(ByVal predicate As Expression(Of Func(Of T, Boolean))) as IQueryable(Of T)

I have 2 concrete Repository's, JobTabRepository and JobUserRepository both implement IRepository

so in the JobTabRepository  which implements IRepository(Of JobTab)

Get(some predicate here) will return a iqueryable(of jobtab).

and JobUserRepository Get(some preditcate) will return IQueryable(of JobUser)

perfectly fine to this point....

now I want to add a method to the JobTabRepository that will return me the JobTab records from the database based on whatever criteria I pass to the predicate, but I want to show the username not the loggedbyid in my final datagrid where the results end up so in essence the result should be the JobTab with its associated JobUser, I wanted to keep the return type of the method as IQueryable(of JobTab) so it keeps the Repository nice and neat, but I cant figure out how to do it keeping the return type a IQueryable(of JobTab).

sorry if this sounds like a lame question, maybe i am just being to strict with what i return from my repository, maybe repository isn't the correct way to go for this problem and i should be looking at something like CQS, I am very new to linqtosql and its associated patterns, but any help would be very much appreciated.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial