views:

178

answers:

1

Im really confused as I have several objects that share a common interface mapped using FNH like so:

            .Where(t => (t.BaseType == typeof(Entity) || t.BaseType == typeof(PipelineStep))
                && t.Namespace.StartsWith("BigNose.Core.Domain") 
                && !t.IsInterface)
            .IgnoreBase<Entity>()
            .IgnoreBase<PipelineStep>()
            .Override<Project>(map => map.HasMany(p => p.Pipelines).Cascade.All())
            .Override<ExpectationProcessingStep>(map =>
                                    {
                                        map.ImportType<IPipelineStep>();
                                        map.ImportType<object>();
                                    })
            ;

Now the odd thing about this mapping is that it seems allow me to query against IPipelineStep using Criteria api, but no with Linq-to-NH or via HQL. For example:

Works (Criteria):

    UoW.Session.CreateCriteria(typeof(IPipelineStep), "p")
     .Add(Restrictions.Eq("p.Pipeline", SampleData.PipelineB))
     .SetMaxResults(10)
     .List<IPipelineStep>()
     .ToList();

This Linq fails:

UoW.Session.Linq<IPipelineStep>()
                           .Where(p => p.Pipeline == SampleData.PipelineB)
                           .ToList();

With exception:

System.InvalidOperationException: Could not find entity named: BigNose.Core.Domain.PipelineSteps.IPipelineStep

BUT, oddly, with out the restriction this works

UoW.Session.Linq<IPipelineStep>()
                           .ToList();

And with HQL it fails even without restrictions:

UoW.Session.CreateQuery("from IPipelineStep p").List<IPipelineStep>()

With exception:

NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: IPipelineStep is not mapped [from IPipelineStep p]

What the heck is going on, and what am I doing soooo wrong.

Thanks in advance, Chris.

A: 

with HQL you need to import the actual interface so it knows about it.

In an HBM file include the following:

<import class="Name.Space.IPipelineStep, Assembly" />

obviously make it make sense first.

Stu
Isn't this is what this section of the FNH : map.ImportType<IPipelineStep>();
Owen