I have a query by linq to nhibernate.
var q = SessionInstance.Query<Evidence>()
.Select(x => new Evidence(x.Id)
{
Type = x.Type,
StartDate = x.StartDate,
EndDate = x.EndDate
})
.ToList();
It has a exception by this Message :
NHibernate.Exceptions.GenericADOException :
Could not execute query[SQL: SQL not available]
{"Exception has been thrown by the target of an invocation."}
{"Specified cast is not valid."}
But by rename Type
property to Type1
, My problem is resolved.
q = q.Select(x => new Evidence(x.Id)
{
Type1 = x.Type1,
StartDate = x.StartDate,
EndDate = x.EndDate
});
Why?
Is a solution exist for use Type
name for a property?
UPDATE: Evidence class is :
public class Evidence
{
public long Id;
public EvidenceEnumType? Type;
public DateTime? StartDate;
public DateTime? EndDate;
}
Stack Trace
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)
at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters)
at NHibernate.Impl.ExpressionQueryImpl.List()
at NHibernate.Linq.NhQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression)
at Remotion.Data.Linq.QueryableBase`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at RCISP.NHibernate.Repository.EvidenceIssuanceRepositoryNh.Search(SearchEvidenceIssuanceDto dto)
at RCISP.Domain.Services.EvidenceIssuanceService.SearchCommand(IRepositoryLocator locator, SearchEvidenceIssuanceDto dto) in D:\Users\Zeynali\Aseman\src\RCISP.Domain\Services\Issuance\EvidenceIssuanceService.cs:line 62
at RCISP.Domain.Services.EvidenceIssuanceService.<>c__DisplayClass4.<Search>b__3(IRepositoryLocator locator) in D:\Users\Zeynali\Aseman\src\RCISP.Domain\Services\Issuance\EvidenceIssuanceService.cs:line 58
at RCISP.NHibernate.TransManager.TransManagerNh.ExecuteCommand[TResult](Func`2 command)