Solved

LinqToSQL, Repository, Asscociations

Posted on 2012-03-29
1
326 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:SniperX1
1 Comment
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37782853
>keeping the return type a IQueryable(of JobTab)

First thing is that if you change the properties of the result set then it will become an anonymous type not JobTab.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question