Solved

LinqToSQL, Repository, Asscociations

Posted on 2012-03-29
1
293 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now