Consider this:
var query = from r in this._db.Recipes where r.RecipesID == recipeID select new { r.RecipesID, r.RecipesName };
How to get individual columns in my queryobject without using a for loop?
query
Basically: how to convert DataTable.Rows[0]["ColumnName"]to Linq syntax?
DataTable.Rows[0]["ColumnName"]
Here's how to do it:
DataContext dc = new DataContext(); var recipe = (from r in dc.Recipes where r.RecipesID == 1 select r).FirstOrDefault(); if (recipe != null) { id = recipe.RecipesID; name = recipe.RecipesName; }
It is not clear what you are looking for since your two samples are compatible.
As I can understand, you want:
var rows = query.ToList(); string name = rows[0].RecipesName;
string name = this._db.Recipes.Single(r => r.RecipesID == recipeID).RecipesName;
, . , ToList(), . , , , , :
query.First().ColumnName
:
var obj = query.FirstOrDefault(); if (obj != null) obj.ColumnName;
( ):
Linq to Datasets. - :
var query = from r in yourTable.AsEnumerable() select r.Field<string>("ColumnName");
Source: https://habr.com/ru/post/1791332/More articles:Trying to use jQuery.addClass method with navigation - javascriptстрока каретки возвращает из сериализации xml в F # - carriage-returnSQL ... How to update rows with data from other rows in one table? - sqlUnderstanding MVC Models - asp.net-mvcHow to get column names from a table returned from a stored procedure - c #End of line behavior in PHP system - phpFind Connected IBAction in Builder Interface - iosWhy are my parameterized queries not working in ASP.NET? - .netContent type cannot be deleted. - content-typeTwo-column dynamic multi-line list floating elements - cssAll Articles