As a workaround, try changing your query to:

ci => ci.Details.OfType<StringDetail>().Any(cd => cd.Name == "DetailName" &&
cd.TypedValue == "Hello")

On Tue, Jan 20, 2009 at 7:05 AM, Tim <[email protected]> wrote:

>
> Hi,
>
> I have a question regarding LINQ to NHibernate. I am using the
> recently released Alpha version of NHibernate.Linq.
>
> I am trying to execute the following query within a Where clause:
>
> ci => ci.Details.Any(cd => cd.Name == "DetailName" && ((StringDetail)
> cd).TypedValue == "Hello")
>
> I am getting this error:
>
> System.InvalidCastException: Invalid cast from 'System.String' to
> 'Zeus.ContentTypes.Properties.ContentDetail'.
>   at System.Convert.DefaultToType(IConvertible value, Type
> targetType, IFormatProvider provider)
>   at System.String.System.IConvertible.ToType(Type type,
> IFormatProvider provider)
>   at System.Convert.ChangeType(Object value, Type conversionType,
> IFormatProvider provider)
>   at System.Convert.ChangeType(Object value, Type conversionType)
>   at NHibernate.Linq.Util.LinqUtil.ChangeType(Object value, Type
> conversionType) in D:\Users\Tim Jones\Downloads\NHibernate.Linq\src
> \NHibernate.Linq\Util\LinqUtil.cs:line 77
>   at NHibernate.Linq.Visitors.BinaryCriterionVisitor.GetBinaryCriteria
> (ICriteria rootCriteria, ISession session, BinaryExpression expr,
> ComparePropToValue comparePropToValue, ComparePropToProp
> comparePropToProp, CompareValueToCriteria compareValueToCriteria,
> ComparePropToCriteria comparePropToCriteria) in D:\Users\Tim Jones
> \Downloads\NHibernate.Linq\src\NHibernate.Linq\Visitors
> \BinaryCriterionVisitor.cs:line 129
>  ...
>
> "Details" is a "list" collection, mapped to an IList<ContentDetail>.
> ContentDetail is an abstract class from which StringDetail inherits.
> The mapping file is as follows:
>
> <class name="Zeus.ContentTypes.Properties.ContentDetail, Zeus"
> table="zeusDetails">
>        ...
>        <subclass name="Zeus.ContentTypes.Properties.StringDetail, Zeus"
> discriminator-value="String">
>                <property name="TypedValue" column="StringValue"
> type="StringClob"
> length="1073741823" />
>        </subclass>
> </class>
>
> I've tried to work out what BinaryCriterionVisitor is doing - it seems
> to be assuming that "Hello" should be converted to a ContentDetail
> object. So I'm guessing that this kind of query is not supported by
> LINQ to NHibernate? Is there any other way of doing this query that is
> supported?
>
> If it's something relatively straightforward, I'd be happy to have a
> go at modifying the NHibernate.Linq code myself.
>
> Thanks for taking the time to read this, and any help with be much
> appreciated.
>
> Tim
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to