score:14
Accepted answer
use this line in your query:
where row.field<decimal?>("parentid") == rootid
decimal?
is syntactic sugar for system.nullable<decimal>
, which is essentially the same as decimal
, except that it also allows for null
values.
long
is a different type altogether -- it can only represent integers and not decimal values, hence the "specified cast is not valid" error.
score:0
long rootid is nullable type? it should be then only it can accept nulls
Source: stackoverflow.com
Related Query
- Linq to DataTable - Cannot cast DBNull
- Object cannot be cast from DBNull to other types Linq
- Object cannot be cast from DBNull to other types in linq expression
- LINQ Source Code Available
- Cannot convert source type to target type List<KeyValuePair> Linq
- Cannot cast from generic to get LINQ where clause
- creating Linq to sqlite dbml from DbLinq source code
- Cannot Cast String to GUID in LINQ to Entities
- CLRSQL Aggregate function. LINQ Code works within CLR Function but cannot be deploy within Aggregate
- Cannot build the Test project for LINQ IQueryable Toolkit (IQToolkit) - Code 9009
- source code for LINQ 101 samples
- Get a list of all DBNull cells of a DataTable with Linq
- Cannot convert source type 'System Linq IQueryable<decimal>' to target type decimal
- Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type. on using Linq Query
- LINQ CopyToDataTable -- Cannot cast DBNull.Value to type 'System.Decimal'. Please use a nullable type
- c# Linq or code to extract groups from a single list of source data
- Cast ITable to IEnuerable<object> - Dynamic LINQ to SQL Query with no DataTable information
- Getting error "Object cannot be cast from DBNull to other types"
- Querying Datatable DBNull using Linq Query
- Unable to cast object of type grouping to datarow after i grouped datatable with linq
- Entity Framework Code First - The entity or complex type cannot be constructed in a LINQ to Entities query
- LINQ query on a DataTable
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Value cannot be null. Parameter name: source
- Filling a DataSet or a DataTable from a LINQ query result set
- LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression
- Linq code to select one item
- Cast LINQ result to ObservableCollection
- How are people unit testing code that uses Linq to SQL
More Query from same tag
- Can someone help me to create a LINQ to XML query?
- Pass ViewBag from Controller to Partial view
- Grouping by an property in a list and the sorting these grouped elements by another property without affecting the original grouping
- Query syntax for getting a list as a list of different types?
- Finding the nth largest in an int array
- LINQ Select distinct on DataTable not working
- I can't understand GroupJoin where i will need it in database relationships
- How can i add linq query EnumerableRowCollection<TRow> to a datatable?
- System.Linq.Dynamic.Core : How do I make a select many correctly?
- Linq with Logic
- How to use Sum on array of strings - LINQ?
- Where is the flaw in my algorithm for consolidating gold mines?
- Changing Combobox should update entity EF6
- I need to Update if exist else Insert with Linq to SQL
- Dictionary requires a model item of type error
- LINQ filter list and exclude MAX value
- Inline LINQ Comments in VB.NET
- Use multiple left joins to set DTO property inside select new linq query
- MVC3 how to update stock of multiple items
- Get details from a LINQ query from Controller to Razor View
- Automapper unable to project one enum type to another
- How to return a list of strings using LINQ
- How to compare all elements between Datatable and Array's months?
- Name doesn't exist in the current context LEFT OUTER JOIN in LINQ
- Filter a list based on a multiple options
- Parsing HTML document: Regular expression or LINQ?
- LINQ to SQL - Get a string from a Var
- How can I use LINQ to select a property inside of an IEnumerable that's inside another IEnumerable?
- Custom predicate building when filtering Kendo UI MVC Grid
- C# Linq - Given two lists, how do I tell if either of them are contained in each other