C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Linq query Posted by jake5958 on 12 Apr 2012 at 1:37 PM
Don't know if this is the correct forum, my apologies if not.

I'm new to LinQ and I'm having trouble converting the following TSQL query to a LinQ query:



SELECT r.*
FROM [Rule] r
INNER JOIN [RuleType] rt
ON r.[RuleTypeId] = rt.[RuleTypeId]
AND rt.[RuleCategoryId] = 1
AND 35 IN (SELECT DISTINCT c.StateId
FROM [Citation] c
WHERE r.[CitationId] = c.[CitationId]
UNION
SELECT DISTINCT a.StateId
FROM [Agency] a
WHERE r.[AgencyId] = a.[AgencyId])



The DB looks like:

--------------- ------------------
| Rule | | Rule Type | ------------------
--------------- -----------------| | RuleCategory |
| RuleId | -----+| RuleTypeId | ------------------
| RuleName | | | RuleCategoryId |>o-------------------+| RuleCategoryId |
| RuleDesc | | | RuleType | | RuleCategory |
| RuleTypeId |>o--| -----------------| -------------- ------------------
| CitiationId |>o------- | Citation |
| AgencyId |>o-- | -------------|
--------------- | |---------------------+| CitationId |
| | Citation |
| | StateID |
| -------------- --------------
| | Agencey | V
| -------------- o
------+| AgencyId | |
| AgencyName | |
| AgencyDesc | |
| StateId |>o-----------\|
-------------- |
|
+
-------------
| State |
-------------
| StateId |
| StateName |
-------------

Report
Re: Linq query Posted by Ajay221990 on 16 Apr 2012 at 11:58 PM
Here is an example for joins in Linq,

This may help you...



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.