Linq error
Linq error
I am having some trouble when generating a linq query against the results of a prior linq query.
The exception that I get is:
System.InvalidCastException was unhandled
Message=Unable to cast object of type 'Devart.Data.Linq.Provider.ProviderType' to type 'Devart.Data.PostgreSql.Linq.Provider.PgSqlProviderType'.
Source=Devart.Data.PostgreSql.Linq
StackTrace:
at Devart.Data.PostgreSql.Linq.Provider.Query.a.a(ProviderType A_0, ProviderType A_1)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.TranslateToServerMethod(List`1 serverMethods, List`1 largeProviderTypes, List`1 arguments, Type returnType)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitMethodCall(bd mc)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitExpression(SqlExpression exp)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitBinaryOperator(av bo)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitBinaryOperator(av bo)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitExpression(SqlExpression exp)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitBinaryOperator(av bo)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitBinaryOperator(av bo)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitExpression(SqlExpression exp)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSelectCore(SqlSelect select)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitSelect(SqlSelect select)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSource(SqlNode source)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSelectCore(SqlSelect select)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitSelect(SqlSelect select)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSequence(SqlSelect sel)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitScalarSubSelect(ad ss)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSubSelect(ad ss)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitExpression(SqlExpression exp)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitRow(af row)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSelectCore(SqlSelect select)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitSelect(SqlSelect select)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.DataProvider.BuildQuery(ResultShape resultShape, Type resultType, SqlNode node, IList`1 externalParameterAccessors)
at Devart.Data.Linq.Provider.DataProvider.BuildQuery(Expression query)
at Devart.Data.Linq.Provider.DataProvider.Devart.Data.Linq.Provider.IProvider.Execute(Expression query)
at Devart.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
Is there any insight you can provide to help be diagnose this problem?
Patrick
The exception that I get is:
System.InvalidCastException was unhandled
Message=Unable to cast object of type 'Devart.Data.Linq.Provider.ProviderType' to type 'Devart.Data.PostgreSql.Linq.Provider.PgSqlProviderType'.
Source=Devart.Data.PostgreSql.Linq
StackTrace:
at Devart.Data.PostgreSql.Linq.Provider.Query.a.a(ProviderType A_0, ProviderType A_1)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.TranslateToServerMethod(List`1 serverMethods, List`1 largeProviderTypes, List`1 arguments, Type returnType)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitMethodCall(bd mc)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitExpression(SqlExpression exp)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitBinaryOperator(av bo)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitBinaryOperator(av bo)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitExpression(SqlExpression exp)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitBinaryOperator(av bo)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitBinaryOperator(av bo)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitExpression(SqlExpression exp)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSelectCore(SqlSelect select)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitSelect(SqlSelect select)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSource(SqlNode source)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSelectCore(SqlSelect select)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitSelect(SqlSelect select)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSequence(SqlSelect sel)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitScalarSubSelect(ad ss)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSubSelect(ad ss)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitExpression(SqlExpression exp)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitRow(af row)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitSelectCore(SqlSelect select)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitSelect(SqlSelect select)
at Devart.Data.Linq.Provider.Query.SqlVisitor.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.DbMethodCallConverter.VisitAlias(e a)
at Devart.Data.Linq.Provider.Query.SqlVisitor.Visit(SqlNode node)
at Devart.Data.Linq.Provider.DataProvider.BuildQuery(ResultShape resultShape, Type resultType, SqlNode node, IList`1 externalParameterAccessors)
at Devart.Data.Linq.Provider.DataProvider.BuildQuery(Expression query)
at Devart.Data.Linq.Provider.DataProvider.Devart.Data.Linq.Provider.IProvider.Execute(Expression query)
at Devart.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
Is there any insight you can provide to help be diagnose this problem?
Patrick
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
Here is a snippet of the code and and observation I was able to make...
At this point q.Count or q.SingleOrDefault will throw the previously posted exception.
Interestingly enough if I comment out the line that checks to see if c.SiteUID is null, the query executes fine.
Note that SiteUID is of type System.Nullable
Code: Select all
var baseQuery = from c in this.vwConfiguration
where c.ConfigurationType.Equals(configurationType) && c.IsExpired.Equals(0)
select c;
baseQuery = from c in baseQuery where c.SiteUID == null select c;
var q = from c in baseQuery
where ((string.IsNullOrEmpty(product) && c.Product == null) || c.Product.Equals(product)) &&
c.SiteUID.Equals(null) &&
((string.IsNullOrEmpty(application) && c.Application == null) || c.Application.Equals(application))
select c;
Interestingly enough if I comment out the line that checks to see if c.SiteUID is null, the query executes fine.
Code: Select all
var q = from c in baseQuery
where ((string.IsNullOrEmpty(product) && c.Product == null) || c.Product.Equals(product)) &&
//c.SiteUID.Equals(null) &&
((string.IsNullOrEmpty(application) && c.Application == null) || c.Application.Equals(application))
select c;
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
This does fix my problem, thank you.
It seems that this might have been a change from .Net 3.5 to .Net 4 as the same code fails in LinqToObjects and it used to work, at least in LinqToSql. Of course I converted my project to .Net 4 at the same time I am trying to convert to PostgreSQL and the invalid cast exception didn't seem to indicate that a null value was the problem...
Thanks again,
Patrick
It seems that this might have been a change from .Net 3.5 to .Net 4 as the same code fails in LinqToObjects and it used to work, at least in LinqToSql. Of course I converted my project to .Net 4 at the same time I am trying to convert to PostgreSQL and the invalid cast exception didn't seem to indicate that a null value was the problem...
Thanks again,
Patrick
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
We have fixed the problem with the '.Equals(null)' translation. The fix is available in the latest 3.0.5 build of LinqConnect, which can be downloaded from
http://www.devart.com/linqconnect/download.html
(the trial only) or from Registered Users' Area (for users with active subscription only).
For more information about the fixes and improvements available in LinqConnect 3.0.5, please refer to
http://www.devart.com/forums/viewtopic.php?t=22168
http://www.devart.com/linqconnect/download.html
(the trial only) or from Registered Users' Area (for users with active subscription only).
For more information about the fixes and improvements available in LinqConnect 3.0.5, please refer to
http://www.devart.com/forums/viewtopic.php?t=22168
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
Yes, it is. The trial of the new dotConnect for PostgreSQL build can be downloaded from
http://www.devart.com/dotconnect/postgr ... nload.html
(other editions are available in Registered Users' Area). For the details about the fixes and improvements, please refer to
http://www.devart.com/forums/viewtopic.php?t=22166
http://www.devart.com/dotconnect/postgr ... nload.html
(other editions are available in Registered Users' Area). For the details about the fixes and improvements, please refer to
http://www.devart.com/forums/viewtopic.php?t=22166