Join With Multiple (OR) Conditions In LINQ To SQL?

Jul 8, 2010

How would I perform this SQL query

Select Distinct s.*
from #ScopeIDs x
Join Scopes s on s.ScopeID=x.ScopeID or x.ScopeID is null

in LINQ to SQL? (This query would return all Scopes whose ScopeID is present in #ScopeIDs, unless one of the entries in #ScopeIDs is null, in which case it returns all Scopes).

A "literal" translation doesn't work, since LINQ doesn't support joining with multiple conditions - code along these lines ...

From x in ScopeIDs
Join s in Scopes on s.ScopeID equals x.ScopeID or x.ScopeID equals nothing
Distinct Select s
... doesn't compile.

View 1 Replies


ADVERTISEMENT

.net - Group Join With Multiple Conditions And One Of Them Being With A Constant?

Jan 29, 2010

Here is a snippet of my (VB) LINQ:

From event_evn In xmlEvents.Descendants("event_evn") _
Join genre_gnr In xmlGenre.Descendants("genre_gnr") On event_evn.Element("evn_gnr_id") Equals genre_gnr.Element("gnr_id").Value _
Group Join eventdata_eda In xmlEventData.Descendants("eventdata_eda") On _
eventdata_eda.Element("eda_evn_id").Value Equals event_evn.Element("evn_id").Value And _
eventdata_eda.Element("eda_dty_id").Value Equals "15" _

[Code]...

View 1 Replies

Access - JOIN Two Tables With Multiple WHERE Conditions

Jun 21, 2010

I have two tables 1) tblRequests and 2.) tblMainTags. The Fields in tblRequests are Tag_Request_No, Employee_ID , Accepted, Accepted_Date, and Accepted_Time. The Fields in tblMaintags are Tag_Request_No, Tag_ID, Completed, ... The fields 'Accepted' and 'Completed' are set to YES/NO.

[Code]...

View 5 Replies

Linq Group By And Order By Multiple Conditions?

Jan 16, 2012

I have the following:

myFilteredContractors = (From c In myFilteredContractors
Join cc In myConClasses On c.ContractorId Equals cc.ContractorId
Where inClassifications.Contains(cc.ClassificationId)[code].....

This is properly ordering this list of contractors by the number of classifications that they have.I also want to order them by whether or not they have a field set (CompanyOverview), which if is an empty string should be below those contractors who have set their CompanyOverview. Also, after the CompanyOverview is ordered I want to order by Registration Date.So it should order by:

Number of Classifications
Whether Overview has been set (c.CompanyOverview)
Registration Date (c.AppliedDate)

Is it possible to all of this in LINQ?

View 1 Replies

Join Multiple Datatables Using LINQ To Dataset?

Feb 8, 2012

I have been searching for quite a while about joining multiple datatables via LINQ to dataset (When i say multiple, i don't mean just 2!!!), and it seems there aren't lot of examples in the net. I have seen examples of joining two datatables, done that, no problem there. Now i want to join three datatables. And there's nothing i can find out there.For example i have a 3 datatables:

PERSON (columns: person_id, name, gender_code, ethnic_code)
GENDER (columns: gender_code, gender_description)
ETHNICITY (cols: ethnic_code, ethnic_description)

[code].....

View 1 Replies

C# - LINQ To SQL Join 3 Tables And Select Multiple Columns And Also Using Sum

Aug 19, 2010

I have three tables Student, TimeSheet and TimeRecord.

Talbe columns:
Student : StudentId, FirstName,
LastName
TimeSheet: TimeSheetId,StudentId, IsActive

[Code].....

View 4 Replies

Sql - Dynamically Varied Number Of Conditions In The 'where' Statement Using LINQ?

Feb 3, 2010

I'm working on my first project using LINQ (in mvc), so there is probably something very simple that I missed. However, a day of searching and experimenting has not turned up anything that works, hence the post.

I'm trying to write a LINQ query (Linq to SQL) that will contain a multiple number of conditions in the where statement separated by an OR or an AND. We don't know how many conditions are going to be in the query until runtime. This is for a search filter control, where the user can select multiple criteria to filter by.

select * from table
where table.col = 1
OR table.col = 2
OR table.col = 7
'number of other conditions

Before I would just construct the SQL query as a string while looping over all conditions. However, it seems like there should be a nice way of doing this in LINQ. I have tried looking using expression trees, but they seem a bit over my head for the moment. Another idea was to execute a lambda function inside the where statement, like so:

For Each value In values matchingRows = matchingRows.Where(Function(row) row.col = value)However, this only works for AND conditions. How do I do ORs?

View 3 Replies

Asp.net - Inner Join Using Linq .net?

Apr 15, 2011

I'm trying to join two datatables of same keyfields.

table1
ID Class
---- -----
1 10
2 9

[code]....

Result

ID Class1 Class2
1 10 8
2 9 7

View 2 Replies

Multiple WHERE Conditions SQL Update

Feb 15, 2012

I'm doing a stock Control System as a school Project using An Access 2007 DB and Visual Studio 2010. I'm trying to do an update Query based on two variables entered into comboboxes, I cannot get the VB to accept the conditions for this, Can anyone Help me?[code]I Cannot get the Code to recognise the Last "'", is there a way to do this?

View 7 Replies

Using Multiple Conditions In The Same For Loop?

May 7, 2010

i want to set 2 conditions for a for loop as i want to loop through the same line of code at the same time . here it is as i have it now

it does not work how i want it to as i want both loops to run simuntaneously instead it runs the first loops continuously before the second and way around this?

For Me.i = 0 To maxrows - 1
For Me.h = 1 To maxrows
Me.Controls.Item("TextBox" & Me.h).Text =

[Code].....

View 1 Replies

Asp.net LINQ Join Query

Sep 28, 2011

I have this query that I tried to join 2 tables together, one which holds the product name, and product numbers, and take a product number, and go to the other where to find a Art_no which is like the product number.[code]

View 2 Replies

Inner Join In Linq To Entities?

Apr 23, 2009

Given two tables, customer and orders, how would one do a linq query to entities to find any customers with open invoices started before a certain date?

View 1 Replies

Join Datatable Using LINQ?

Jan 13, 2011

I have two DataTables:

dt1 - personid, name

dt2 - personid

I want to create a third datatable to include records from dt1 when they are NOT in dt2 using LINQ. In this case, I can bind the third datatable to a dropdownlist.

View 1 Replies

Multiple Conditions With A SELECT From Where Query?

Mar 30, 2010

I am trying to link to a Access database at runtime using a SELECT FROM WHERE query, which I can do but.......

with the WHERE part I want to select several conditions, 4 actually and it is not working, what am I doing wrong?

Here is my code,

Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=V:GYMDBFLineProdSanderProduction.mdb")

[Code]....

View 2 Replies

VS 2008 Multiple If Not Conditions On One Line?

Apr 15, 2010

How can I have multiple If Not conditions on one line?

Here are the combinations that I've tried, but they either don't work, or won't build.

If Not (txtDisplay.Text = "0") And If Not (txtDisplay.Text = "")
statement1
Else

[Code]....

View 3 Replies

Linq Join On Mutliple Properties

Jun 16, 2009

Are the below two queries functionally the same?The first one doesn't return any data, but the second works fine with same exact input.Can someone point out what's wrong in my first query? [code]

View 2 Replies

C# - Join The Objects In A LINQ Expression?

Dec 15, 2011

How to Join the objects in a LINQ select in this sample (C# variants accepted as well):

Class Room
Public Area As Integer
End Class
Class RoomPair

[code]....

View 4 Replies

C# - Linq To Objects Outer Join?

Mar 10, 2010

Im trying to use LINQ to query Objets. I'm doing the following:

Dim myList As Generic.List(Of MyItem) = (From ThisItem In LinqToSqlObject.Items _
Join Folder In LinqToSqlObject.Folders _
On Folder.Id Equals Item.Id _

[Code]....

This however will not return any item that has a ParentItemId of null. I am trying to do a left join so as to return all "Item" regardless of whether it has a parent or not. I am aware that this is feasible in C# by adding an "into X" on the join, and selecting from X.DefaultIfEmpty(), this however does not appear to work in VB.Net.

View 2 Replies

Left Join Linq To Entity's .net?

Apr 11, 2011

I can't figure out that linq to entity query syntax. My problem is that if the value of the Calls table is null then noting comes up, I want to make something like a left join to get 'all' rows from the Calls table.I tried to group it but I can't figure out the correct way to write it.

Dim TicketQuery As ObjectQuery = From c In EnData.Customer _
Join t In EnData.Calls On t.CustomerID Equals c.CustomerID _
Join Status In EnData.Lists On t.Status Equals Status.ListValue _

[code].....

View 1 Replies

LINQ Dataset LEFT JOIN?

Jun 14, 2012

i think i have not represented my question correctly here My LEFT OUTER JOIN MSDN reference is here to visualize my problem in access databaseTABLE "T1"1234567TABLE "T2"1,sunday2,monday i need output as 1,sunday2,monday34567 i need it to done through LINQso far i did is here

Dim RIGHT_table As DataTable = ds1.Tables("t1")
Dim LEFT_table As DataTable = ds2.Tables("T2")
Dim OutPut = From LEFTsource In LEFT_table.AsEnumerable(), RIGHTsource In RIGHT_table.AsEnumerable() _

[code]...

View 3 Replies

Linq Join On Parameterized Distinct Key?

Sep 9, 2010

I'm trying to LINQ two tables based on a dynamic key. User can change key via a combo box. Key may be money, string, double, int, etc. Currently I'm getting the data just fine, but without filtering out the doubles. I can filter the double in VB, but it's slooooow. I'd like to do it in the LINQ query right out of the gate.

[Code]...

"Range variable name can be inferred only from a simple or qualified name with no arguments."

View 3 Replies

Linq Join On Parametrized Distinct Key?

Jun 9, 2011

I'm trying to LINQ two tables based on a dynamic key. User can change key via a combo box. Key may be money, string, double, int, etc. Currently I'm getting the data just fine, but without filtering out the doubles. I can filter the double in VB, but it's slooooow. I'd like to do it in the LINQ query right out of the gate.

LinqMasterTable:
-------------------------------------------------------------
| AppleIndex | AppleCost | AppleColor | AppleDescription |
------------------------------------------------------------

[Code].....

View 1 Replies

Linq Left Outer Join?

Apr 21, 2011

I ultimately what I needed is generic function which would take two datatable and and 2 tablekeys and return Joined datatable. So here is my first step to solve it.

How Can I write Linq example of following T-SQL example in VB?

SELECT * FROM
Table1
LEFT OUTER JOIN
Table2
ON Table1.key = Table2.key

View 2 Replies

LINQ To SQL And Join Two Tables With OR Clause

Apr 23, 2009

Let's say I have Plans and Documents
Dim myPlans = _context.Plans.Where(predicate1)
Dim myDocuments = _context.Documents.Where(predicate2)

I have structured the where clause for each using PredicateBuilder. So, myPlans and myDocuments have a correct SQL statement. What I'd like to do is join these two tables into one linq statement. The problem I'm having is that, by default the AND condition is joining the where clauses.

myPlans Where clause : (p.name like "%test%" AND p.name like "%bed%") OR (p.description like "%test%" AND p.description like "%bed%")
myDocuments Where clause : (d.name like "%test%" AND d.name like "%bed%") OR (d.description like "%test%" AND d.description like "%bed%")

When I combine the two the desired result Where clause is:
Where (d.ID = p.ID) AND
(myplans where clause above) OR (mydocument where clause above). Meaning, I'd like the two where clauses in each of the tables to be "or" instead of "And".

The current result where clause is:
Where (d.ID = p.ID) AND
(myplans where clause above) AND (mydocument where clause above). Meaning, I'd like the two where clauses in each of the tables to be "or" instead of "And".

I'm forming the statement like this:
Dim test = From d in myDocuments _
Join p in MyPlans on d.ID Equals p.ID _
Select d.Name, p.Name

View 2 Replies

LINQ To SQL Left Outer Join VB?

Nov 9, 2011

I cannot get this to work with LINQ to SQL vb.net?

SELECT a.FLD_ID, a.FLD_SUBJECT, a.FLD_GROUP, a.FLD_SUBMITTED, a.FLD_LASTACTION, a.FLD_CLOSED
FROM TBL_WSS_TT_TICKET a LEFT OUTER JOIN
TBL_WSS_TT_ALLOW b ON a.FLD_ID = b.FLD_TICKET_REF
WHERE (a.FLD_USER = 'user') OR (b.FLD_USER = 'user')

View 10 Replies

Sql Server :: LINQ To SQL Get Grouped MIN With JOIN?

Apr 19, 2010

I'm having trouble with a LINQ to SQL query getting the min value using Visual Basic. Here's the SQL:

SELECT RC.AssetID, MIN(RC.RecCode) AS RecCode, JA.EngineerNote from JobAssetRecCode RC
JOIN JobAssets JA ON JA.AssetID = RC.AssetID AND JA.JobID = RC.JobID
WHERE RC.InspState = 2 AND RC.RecCode > 0

[code]....

View 1 Replies

Use LINQ To Left Join 2 Datatables?

Nov 10, 2011

I have two UNTYPED datatables: "Shelfs" and "Books". Data came from different databases.

I must create a "left join" relationship because I want a list of ALL shelfs and books (if they have any).

Dim dset As New DataSet
dset.Tables.Add(dtShelfs)
dset.Tables.Add(dtBooks)

[Code].....

I spent hours googling around, but all examples I found were only applicable to strongly typed dataSets, and how to build queries (not to get the data)

I could solve this the "easy" way: by looping both datatables and sending the rows to a third one, but I want to do this the "right" way and, of course... LINQ exists to make things easier and I don't know how to use it

View 4 Replies

Forms :: Managing Multiple Conditions In IF - Then Statement

Oct 19, 2010

I currently have an If...Then statement that checks if all fields of a form have been filled before saving the info in a file. I'd like to be able to tell which field has not been filled to give the user a dynamic message (at the moment, it only tells them that the checklist is not completed ) :

If (txtNoDemande.TextLength = 8 _
Or txtNoDemande.TextLength = 13 _
And txtDateLoad.TextLength <> 0 _

[CODE]...

Is there a way to determine which of these conditions is false without having to do a seperate If statement for each ?

View 2 Replies

VS 2008 Creating A SQL Statement With Multiple WHERE Conditions?

Feb 27, 2010

I am trying to write a Function which will return a data table, filled with a data from a database.

The Function will accept 6 diffrenet parameters as Optional. Each one of them will be an additional condition to be added to a where clause, if it`s provided when the function is beeing called.

Is there any method in .NET to simply add a new condition to the where clause?

View 10 Replies

VS 2010 - Multiple Conditions For Select Case

Jun 26, 2010

I'm programming a utility for a game, and at the moment I am adding chat commands for it. They use the Select Case type, but I want to be able to use multiple conditions for 1 case.

Current
Case "/lame"
If sParameter = "announce" Then
AnnounceMsg("^1No Laming
^7Laming consists of
^5* ^7Attacking someone with
^5- ^7Weapon Down
^5- ^7Chatbubble Up")
[Code] .....

I get an error:
Conversion from string "/lame" to type 'Long' is not valid.

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved