sooprise
sooprise

Reputation: 23187

C# LINQ join With Just One Row

I'm trying to make a query that grabs a single row from an SQL database and updates it.

TableA
AId
AValue

TableB
BId
AId
BValue

Ok, so TableA and TableB are linked by AId. I want to select a row in TableB based on AValue using a join. The following query is what I have and only grabs a value from TableB based on AId, I just don't know how to grab a row from TableB using AValue. I know you would need to use a join, but I'm not sure how to accomplish that.

var row = DbObject.TableB.Single(x => x.AId == 1)
row.BValue = 1;
DbObject.SubmitChanges();

Upvotes: 2

Views: 2830

Answers (1)

Taylor Leese
Taylor Leese

Reputation: 52290

Below is a LINQ query to do what you are asking.

var row = (from b in TableB
        join a in TableA on a.AId equals b.AId
        where a.AValue = yourValue).Single();

Upvotes: 1

Related Questions