Skip to content

NH-3200 - Exception in linq query for use "Type" for property name #1280

Open
@nhibernate-bot

Description

@nhibernate-bot

Ehsan Zeynali created an issue — 26th June 2012, 4:55:39:

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
        });

My 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(Expression expression)
at Remotion.Data.Linq.QueryableBase1.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList<TSource>(IEnumerable1 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.b__3(IRepositoryLocator locator) in D:\Users\Zeynali\Aseman\src\RCISP.Domain\Services\Issuance\EvidenceIssuanceService.cs:line 58
at RCISP.NHibernate.TransManager.TransManagerNh.ExecuteCommand(Func`2 command)

Why?
Is a solution exist for use Type name for a property?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions