score:1
below code is working for me.
thanks every one
var commonrows = from r1 in dt.asenumerable()
join r2 in tempdt.asenumerable()
//on r1.field<object>(0).tostring() equals r2.field<object>(4).tostring()
on r1[0].tostring() equals r2[4].tostring()
select r2;
if (commonrows.any())
{
abcdefgh = commonrows.count();
dt123 = commonrows.copytodatatable();
// ring the ghanta of gutlu
}
score:0
field expects the underlying datatype to be a string.
see: http://msdn.microsoft.com/en-us/library/bb301394.aspx
invalidcastexception
the value type of the underlying column could not be cast to the type specified by the generic parameter, t.
you could use object to ignore the type as jens kloster purposed. however, there is something wrong with your design if you don't know the datagtype of your columns.
score:0
this error is caused by a mismatch datatypes between properties' entity and underlying table columns.
score:2
casting to string isn't really possible, since double and string are 2 completely unrelated classes. perhaps try comparing their .tostring() values. or if you want to be completely safe, compare their string formats, so you don't get any nullreferenceexceptions: string.format("{0}", fieldvalue)
score:6
here is where i think your problem is:
from r1 in dt.asenumerable()
join r2 in tempdt.asenumerable() on
r1.field<string>(0) //<-- this may not be string
equals
r2.field<string>(4) //<-- this may not be string
select r2;
what you could do is to treat it as object:
from r1 in dt.asenumerable()
join r2 in tempdt.asenumerable() on
(string.empty + r1.field<object>(0)) <-- edited by andreas x
equals
(string.empty + r2.field<object>(4)) <-- edited by andreas x
select r2;
what you should do, is to make sure your index numbers (0 and 4) points to the same type.
edit: i usually use the old asp-trick to aboid null pointers when asking to the tostring value.
Source: stackoverflow.com
Related Query
- Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[]' using linq lambda expression
- Linq cast conversion Xelement error: Unable to cast object of type 'System.Xml.Linq.XElement' to type 'System.IConvertible'
- Unable to cast object of type 'WhereSelectListIterator` in LINQ
- LINQ Issue: Unable to cast object of type 'System.Reflection.Module' to type 'System.Reflection.Emit.ModuleBuilder
- Removing duplicates using LINQ returns "Error removing duplicates: Unable to cast object of type 'System.Int32' to type 'System.String'."
- LINQ with String.Join() error: "System.InvalidCastException: Unable to cast object of type '<DistinctIterator>
- linq query getting Unable to cast object of type 'System.Boolean' to type 'System.String'
- Unable to cast object of type 'System.Double' to type 'System.String' linq query
- Unable to cast object of type 'System.Int32' to type 'System.String' in LINQ query
- Assigning LINQ Results to child Property - InvalidCastException: Unable to cast object of type
- LINQ Error unable to cast object of type 'system.datetime' to type 'system.string'
- Unable to cast object of type in below Linq method
- Unable to cast object of type grouping to datarow after i grouped datatable with linq
- Unable to cast string type to number type in Linq expression
- Linq query error - Unable to cast object of type 'V1.Controllers.Loan' to type 'System.IConvertible
- Unable to cast object of type 'System.Linq.Expressions.UnaryExpression' to type 'System.Linq.Expressions.MemberExpression'
- Unable to cast object of type WhereSelectListIterator 2 System.Collections.Generic.List
- Unable to cast object of type 'System.Data.Linq.DataQuery`1[System.Int32]' to type 'System.IConvertible'
- Unable to cast object of type 'WhereEnumerableIterator`1' to type 'System.Collections.Generic.ICollection`1
- Unable to cast object of type 'System.Collections.Generic.List`1[System.Decimal]' to type 'System.IConvertible'
- Unable to cast object of type 'System.Int32' to type 'System.String'
- Unable to cast a object of type 'SZArrayEnumerator' to type 'System.Collections.Generic.IEnumerator' 1[System.String]'
- Unable to cast object of type WhereSelectListIterator
- Unable to cast object of type 'System.Linq.EnumerableQuery to type 'Microsoft.Azure.Documents.Linq.IDocumentQuery
- Unable to cast object of type System.Func`2 with Int64
- Unable to cast object of type '<>f__AnonymousType5`6
- Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.IDataReader'
- Unable to cast object of type 'System.Int16' to type 'System.String'
- Unable to cast object of type 'System.Data.Objects.ObjectQuery`1 [Manager.Data.Channel]' to type 'Manager.Data.Channel'
- Unable to cast the type X to type Y. LINQ to Entities only supports casting EDM primitive or enumeration types
More Query from same tag
- Linq sum by variable number of monthS or weekS
- How to select only specific properties of navigation property
- select all fields from ilist, contains list of objects
- Join with Entity Framework and F#
- Pagination with LINQ on Stored Procedures?
- Dynamic Linq to OrderBy Object Nested in IEnumerable
- How can I filter the elements in the list by certain criteria and then change their properties with Linq?
- How to pass an external parameter to LINQ where clause in CRM
- How to remove duplicates in a list while keeping elements with highest scores among duplicates, in C# with Linq
- Concatenate string property of a custom object from json array
- Can I "stop" a LINQ method chain midway?
- Values returned from my Repository model class is being cached
- SQL Server RowVersion
- LINQ Contains vs Intersect (vs anything else!)
- LINQ support in Enterprise Library Data Access Application Block
- How to sort a list by a specific property in .NET 2.0?
- how to display posts by month asp.net mvc
- Which namespace to include to strongly type the property with DbEntityEntry.Property
- Converting nested loop to LINQ statement
- C#: Mapping a Data Type
- Find record position in Linq2Sql or Entity framework query
- Difference between DataView.Sort and DataTable.OrderBy().AsDataView()?
- Column Selection In Generic Repository Class
- Top one row in group set with Entity framework core
- Optimizing the LINQ expressions
- Linq to SQL: DataTable.Rows[0]["ColumnName"] equivalent
- EF6 Single LINQ Query for nested Lists
- LINQ: Entity string field contains any of an array of strings
- How do I grab only the latest Invoice Number
- ConnectionString switching within partial class for dbml