How should I write this in LINQ?
I have three tables I'm getting info from: User, Field, FieldUserInput. I already know the userId which is what I use to find out what fields the user has input. Then I want to get the value of those fields that the user has input in FieldUserInput.
I first wrote this query in plain old sql but I want to use LINQ as much as possible since that's why I use Entity Framework.
SELECT fielduserinput.field_idField, fielduserinput.userInput, fielduserinput.time FROM fielduserinput WHERE fielduserinput.userId = @userId
Any suggestions as to how I would write this in LINQ?开发者_运维知识库
Considering you have a datasource filled with data.
var matchingRows = from rows in fielduserinput.AsEnumarable()
where string.compare(rows["userId"].ToString(),userID)==0
select rows;
var result = from row in fielduserinput
where row.userId = "???"
select new { row.field_idField, row.userInput, ...};
var response = fielduserinput
.Where(x=>x.userid == @userid)
.Select(x=>new { field_idfieldid = x.field_idfieldid, etc })
.ToList()
精彩评论