Solved

LinqToSQL, Repository, Asscociations

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - KeyPress Event 4 37
VB.NET 1 24
Need help with a Crystal Report in my C#.Net application 2 16
Dot Net 4.6.1 installation fails on W2012 R2 server 14 20
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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