Hi,
We've a mature nHibernate project that has started using the linq provider in nHibernate contrib. As we are using nHibernate 2.0 we can't use the new provider under development in the trunk (against nHibernate 3.0).
Whilst limited it's proved to be a perfect for our needs apart from one issue - whenever I select a CompositeUserType I get an error ''
I'm not sure the Linq to nHibernate provider v1 can understand these types. Does anyone know for sure ? UI'm trying with the source and not finding much joy. I'm hoping someone can help and show me how.
And now the example.... for the given ActiveRecord type...
[ActiveRecord]
public class Product : IHoldPrice
{
[PrimaryKey(PrimaryKeyType.Guid)]
public virtual Guid Key { get; set; }
[Property(NotNull = true, Length = 250)]
public virtual string Name { get; set;}
[CompositeUserType(typeof (PriceUserType), new[] {"Price_Value", "Price_DateChanged"})]
public virtual IPrice CurrentPrice { get; set; }
}
When I try the following statement I get an error:
(from p in Session.Linq<Product>()
.Where(p => p.Key == productKey)
.Select(p => new
{
p.Key,
p.CurrentPrice
}))
.FirstOrDefault();
Error:
‘property does not map to a single column: CurrentPrice’
Stack: ‘property does not map to a single column: CurrentPrice’
Stack:
NHibernate.QueryException: property does not map to a single column: CurrentPrice
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumn(ICriteria criteria, String propertyName)
at NHibernate.Criterion.PropertyProjection.ToSqlString(ICriteria criteria, Int32 loc, ICriteriaQuery criteriaQuery, IDictionary`2 enabledFilters)
at NHibernate.Criterion.ProjectionList.ToSqlString(ICriteria criteria, Int32 loc, ICriteriaQuery criteriaQuery, IDictionary`2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetSelect(IDictionary`2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor factory, ICriteria criteria, String rootEntityName, IDictionary`2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary`2 enabledFilters)
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
at NHibernate.Impl.CriteriaImpl.List(IList results)
at NHibernate.Impl.CriteriaImpl.List[T]()
at NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.GetElementList(MethodCallExpression call, Int32 count)
at NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.HandleFirstOrDefaultCall(MethodCallExpression call)
at NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.VisitMethodCall(MethodCallExpression call)
at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
at NHibernate.Linq.Visitors.ImmediateResultsVisitor`1.GetResults(MethodCallExpression expr)
at NHibernate.Linq.Visitors.RootVisitor.HandleImmediateResultsCall(MethodCallExpression call)
at NHibernate.Linq.Visitors.RootVisitor.VisitMethodCall(MethodCallExpression expr)
at NHibernate.Linq.Visitors.ExpressionVisitor.Visit(Expression exp)
at NHibernate.Linq.Visitors.NHibernateExpressionVisitor.Visit(Expression exp)
at NHibernate.Linq.Visitors.NHibernateQueryTranslator.Translate(Expression expression, QueryOptions queryOptions)
at NHibernate.Linq.NHibernateQueryProvider.TranslateExpression(Expression expression)
at NHibernate.Linq.NHibernateQueryProvider.Execute(Expression expression)
at NHibernate.Linq.QueryProvider.System.Linq.IQueryProvider.Execute[T](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
Note - No I can't use Criteria and no Hql won't do right now, and I know the new Linq provider is much better.