-
Notifications
You must be signed in to change notification settings - Fork 113
Closed
Description
LINQ
from current in repository.EngineeringCircuitEnds
from previous in repository.EngineeringCircuitEnds
where current.Gender == previous.Gender
select new { CurrentId = current.EngineeringCircuitID, PreviousId = previous.EngineeringCircuitID };SQL
Can't generate
Problems
Exception:
System.InvalidCastException : Unable to cast object of type 'System.Linq.Expressions.PropertyExpression' to type 'System.Linq.Expressions.ConstantExpression'.
Workarounds
A workaround for problem is to handle null case manually:
from current in repository.EngineeringCircuitEnds
from previous in repository.EngineeringCircuitEnds
where (current.Gender ?? ' ') == (previous.Gender ?? ' ')
select new { CurrentId = current.EngineeringCircuitID, PreviousId = previous.EngineeringCircuitID };Generated expression file
//---------------------------------------------------------------------------------------------------
// This code was generated by BLToolkit.
//---------------------------------------------------------------------------------------------------
using System;
using System.Linq.Expressions;
using NUnit.Framework;
namespace SPX.DEF.FromTo.UnitTest
{
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
class <>c__DisplayClassf
{
public SPX.GCIS.Data.Sql.SqlServerDataRepository repository;
}
}
namespace SPX.GCIS.Data.Sql
{
[BLToolkit.DataAccess.TableNameAttribute(Name = "EngineeringCircuitEnd")]
public class EngineeringCircuitEndRecord
{
[BLToolkit.DataAccess.PrimaryKeyAttribute((Int32)1)]
[BLToolkit.DataAccess.IdentityAttribute()]
public Int64 EngineeringCircuitID { get; set; }
[BLToolkit.Mapping.NullableAttribute()]
public Char? Gender { get; set; }
}
}
namespace SPX.GCIS.Data.Sql
{
public class SqlServerDataRepository : BLToolkit.Data.DbManager, System.ComponentModel.IComponent, IDisposable, BLToolkit.Data.Linq.IDataContext, BLToolkit.Mapping.IMappingSchemaProvider
{
public SqlServerDataRepository()
{
throw new NotImplementedException();
}
public SqlServerDataRepository(string connectionString)
{
throw new NotImplementedException();
}
public SqlServerDataRepository(System.Data.IDbConnection connection)
{
throw new NotImplementedException();
}
public BLToolkit.Data.Linq.Table<SPX.GCIS.Data.Sql.EngineeringCircuitEndRecord> EngineeringCircuitEnds { get; set; }
}
}
namespace Data.Linq
{
[TestFixture]
public class UserTest : TestBase
{
[Test]
public void Test()
{
// Table(EngineeringCircuitEndRecord).SelectMany(current => value(SPX.DEF.FromTo.UnitTest.BlToolkitTesting+<>c__DisplayClassf).repository.EngineeringCircuitEnds, (current, previous) => new <>f__AnonymousTypea`2(current = current, previous = previous)).Where(<>h__TransparentIdentifiere => (Convert(<>h__TransparentIdentifiere.current.Gender) == Convert(<>h__TransparentIdentifiere.previous.Gender))).Select(<>h__TransparentIdentifiere => new <>f__AnonymousTypeb`2(CurrentId = <>h__TransparentIdentifiere.current.EngineeringCircuitID, PreviousId = <>h__TransparentIdentifiere.previous.EngineeringCircuitID))
ForEachProvider(db =>
Table(EngineeringCircuitEndRecord)
.SelectMany(
(SPX.GCIS.Data.Sql.EngineeringCircuitEndRecord current) => value(SPX.DEF.FromTo.UnitTest.BlToolkitTesting+<>c__DisplayClassf).repository.EngineeringCircuitEnds,
(SPX.GCIS.Data.Sql.EngineeringCircuitEndRecord current, SPX.GCIS.Data.Sql.EngineeringCircuitEndRecord previous) => new
{
current = current,
previous = previous
})
.Where(
(tpe) => ((int?)tpe.current.Gender == (int?)tpe.previous.Gender))
.Select(
(tpe) => new
{
CurrentId = tpe.current.EngineeringCircuitID,
PreviousId = tpe.previous.EngineeringCircuitID
}));
}
}
}Metadata
Metadata
Assignees
Labels
No labels