linq-to-dataset

LINQ to DataSet, distinct by multiple columns

穿精又带淫゛_ 提交于 2019-11-28 19:44:35
Just wanted to check if there is way to do distinct by multiple columns. Thanks in advance!!! BTW, I found a great LINQ extension here but need some guidance to use it for multiple columns Well, you can do the projection first: var qry = db.Customers.Select(cust => new {cust.ID, cust.Name, cust.Region}) .Distinct(); Or in query syntax: var qry = (from cust in db.Customers select new {cust.ID, cust.Name, cust.Region}).Distinct(); That do? Pradeep Instead of Distinct you can use Groupby and then selecting the Top Most record of each group How to LINQ Distinct by Multiple Fields without anonymous

Select distinct rows from datatable in Linq

萝らか妹 提交于 2019-11-28 01:48:38
I am trying to get distinct rows based on multiple columns (attribute1_name, attribute2_name) and get datarows from datatable using Linq-to-Dataset. I want results like this attribute1_name attribute2_name -------------- --------------- Age State Age weekend_percent Age statebreaklaw Age Annual Sales Age Assortment How to do thin Linq-to-dataset? If it's not a typed dataset, then you probably want to do something like this, using the Linq-to-DataSet extension methods: var distinctValues = dsValues.AsEnumerable() .Select(row => new { attribute1_name = row.Field<string>("attribute1_name"),

Fill Datatable from linq query

折月煮酒 提交于 2019-11-28 01:40:58
i am using the below code IEnumerable<DataRow> query = from c in at.appointmentcalendars.AsEnumerable() select c; DataTable dt = query.CopyToDataTable(); But i am getting the below error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<appointmentcalendar>' to 'System.Collections.Generic.IEnumerable<System.Data.DataRow>' . An explicit conversion exists (are you missing a cast?) terrybozzio Since the query returns an IEnumerable of Type DataRow, you have to specify what to insert into the datatable, in this case DataRow. DataTable dt = query.CopyToDataTable<DataRow>(); If

DataTable does not contain definition for AsEnumerable

谁都会走 提交于 2019-11-27 13:52:43
Using linq to query a datatable returns the following error: CS0117: 'DataSet1.map DataTable' does not contain a definition for 'AsEnumerable' Project includes reference for System.Data.Datasetextensions. Here's the code. using System; using System.Collections; using System.ComponentModel; using System.Configuration; using System.Reflection; using System.Data; using System.Linq; using System.Data.Linq; using System.Data.Common; using System.Data.DataSetExtensions; using System.Linq.Expressions; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls;

How I can filter a dataTable with Linq to datatable?

大憨熊 提交于 2019-11-27 12:59:41
问题 hi how i can filter a datatable with linq to datatable? I have a DropDownList and there I can select the value of the Modul Column. Now I want to filter the DataTable with this Modul Column. here is my datatable structure: User | Host | TimeDiff | License | Telefon | Modul Here the Code: protected void drp_Modules_SelectedIndexChanged(object sender, EventArgs e) { string value = drp_Modules.SelectedValue; DataTable tb = (DataTable)Session["dt_Users"]; tb = from item in tb //?????

LINQ to DataSet, distinct by multiple columns

本小妞迷上赌 提交于 2019-11-27 12:46:42
问题 Just wanted to check if there is way to do distinct by multiple columns. Thanks in advance!!! BTW, I found a great LINQ extension here but need some guidance to use it for multiple columns 回答1: Well, you can do the projection first: var qry = db.Customers.Select(cust => new {cust.ID, cust.Name, cust.Region}) .Distinct(); Or in query syntax: var qry = (from cust in db.Customers select new {cust.ID, cust.Name, cust.Region}).Distinct(); That do? 回答2: Instead of Distinct you can use Groupby and

Binding LINQ query to DataGridView

时光总嘲笑我的痴心妄想 提交于 2019-11-27 02:25:59
问题 This is very confusing, I use AsDataView to bind query result to a dgv and it works fine with the following: var query = from c in myDatabaseDataSet.Diamond where c.p_Id == p_Id select c; dataGridView1.DataSource = query.AsDataView(); However, this one results in an Error: var query = from item in myDatabaseDataSet.Items where item.p_Id == p_Id join diamond in myDatabaseDataSet.Diamond on item.p_Id equals diamond.p_Id join category in myDatabaseDataSet.DiamondCategory on diamond.dc_Id equals

Fill Datatable from linq query

╄→尐↘猪︶ㄣ 提交于 2019-11-26 23:34:16
问题 i am using the below code IEnumerable<DataRow> query = from c in at.appointmentcalendars.AsEnumerable() select c; DataTable dt = query.CopyToDataTable(); But i am getting the below error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<appointmentcalendar>' to 'System.Collections.Generic.IEnumerable<System.Data.DataRow>' . An explicit conversion exists (are you missing a cast?) 回答1: Since the query returns an IEnumerable of Type DataRow, you have to specify what to

Select distinct rows from datatable in Linq

≡放荡痞女 提交于 2019-11-26 22:03:06
问题 I am trying to get distinct rows based on multiple columns (attribute1_name, attribute2_name) and get datarows from datatable using Linq-to-Dataset. I want results like this attribute1_name attribute2_name -------------- --------------- Age State Age weekend_percent Age statebreaklaw Age Annual Sales Age Assortment How to do thin Linq-to-dataset? 回答1: If it's not a typed dataset, then you probably want to do something like this, using the Linq-to-DataSet extension methods: var distinctValues

DataTable does not contain definition for AsEnumerable

喜欢而已 提交于 2019-11-26 16:31:33
问题 Using linq to query a datatable returns the following error: CS0117: 'DataSet1.map DataTable' does not contain a definition for 'AsEnumerable' Project includes reference for System.Data.Datasetextensions. Here's the code. using System; using System.Collections; using System.ComponentModel; using System.Configuration; using System.Reflection; using System.Data; using System.Linq; using System.Data.Linq; using System.Data.Common; using System.Data.DataSetExtensions; using System.Linq