Microsoft Developer Network >
Forums Home
>
Archived Forums Forums
>
LINQ Project General
>
call is ambiguous between the following methods
call is ambiguous between the following methods
- Greetings!
I'm working with LINQ and I "copied" a class from a blog that would convert the IEnumerable information from a LINQ query to a DataTable, and I'm getting an error that I just cannot get.
After looking for answers, I read an article that suggests this bug is because of VS 2008 as it does not happen in VS 2005.
I would like to know the opinion of the members of this forum and see if there is a workaround.
The following is the Error, and after that I will post my code. Thank you so much!
CS0121: The call is ambiguous between the following methods or properties: 'CustomerPriceAgreement.ConvertDataTable.ToADOTable<AnonymousType#1>(System.Collections.Generic.IEnumerable<AnonymousType#1>, CustomerPriceAgreement.ConvertDataTable.CreateRowDelegate<AnonymousType#1>)' and 'CustomerPriceAgreement.ConvertDataTable.ToADOTable<AnonymousType#1>(System.Collections.Generic.IEnumerable<AnonymousType#1>, CustomerPriceAgreement.ConvertDataTable.CreateRowDelegate<AnonymousType#1>)'
CODE
public static DataSet BindCustomerGrid(DataSet ds, bool expired) { DataTable dtCutomers = new DataTable(); dtCutomers = CreateDataTableCustomers(dtCutomers); PriceCustomerAgreementDataContext PCA = new PriceCustomerAgreementDataContext(); PriceCustomerAgreement_Customer customer = new PriceCustomerAgreement_Customer(); var query = from customers in PCA.PriceCustomerAgreement_Customers select new { customers }; if (expired) { //d = date query = query.Where(d => d.customers.ExpDate < DateTime.Today); } var PriceCustomerAgreement = from rows in query select new { rows.customers.ID, rows.customers.Customer, rows.customers.PartNumber, rows.customers.Price, rows.customers.Qty, EntryDate = rows.customers.EntryDate.Value.ToShortDateString(), rows.customers.SystemUser, rows.customers.Notes, ExpDate = rows.customers.ExpDate.Value.ToShortDateString() }; DataTable dt = PriceCustomerAgreement.ToADOTable(rec => new object[] { PriceCustomerAgreement }); } namespace CustomerPriceAgreement { public static class ConvertDataTable { public static DataTable ToADOTable<T>(this IEnumerable<T> varlist, CreateRowDelegate<T> fn) { DataTable dtReturn = new DataTable(); // Could add a check to verify that there is an element 0 T TopRec = varlist.ElementAt(0); // Use reflection to get property names, to create table // column names PropertyInfo[] oProps = ((Type)TopRec.GetType()).GetProperties(); foreach (PropertyInfo pi in oProps) { Type colType = pi.PropertyType; if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>))) { colType = colType.GetGenericArguments()[0]; } dtReturn.Columns.Add(new DataColumn(pi.Name, colType)); } foreach (T rec in varlist) { DataRow dr = dtReturn.NewRow(); foreach (PropertyInfo pi in oProps) { dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null); } dtReturn.Rows.Add(dr); } return (dtReturn); } public delegate object[] CreateRowDelegate<T>(T t); } }
Eduardo
Answers
- Try:
DataTable dt = PriceCustomerAgreement.AsEnumerable().ToADOTable(...
...at the end of BindCustomerGrid...
Kristofer - Huagati Systems Co., Ltd.
Cool tools for Linq-to-SQL and Entity Framework:
huagati.com/dbmltools (add-in with new features for Visual Studio 2008's L2S and EF designers)
huagati.com/L2SProfiler (Query profiler for Linq-to-SQL and LLBLGen Pro)- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 4:20 AM
All Replies
- Nobody?
Eduardo - Try:
DataTable dt = PriceCustomerAgreement.AsEnumerable().ToADOTable(...
...at the end of BindCustomerGrid...
Kristofer - Huagati Systems Co., Ltd.
Cool tools for Linq-to-SQL and Entity Framework:
huagati.com/dbmltools (add-in with new features for Visual Studio 2008's L2S and EF designers)
huagati.com/L2SProfiler (Query profiler for Linq-to-SQL and LLBLGen Pro)- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 4:20 AM

