开发者

NHibernate Criteria API with unmapped tables

I have a class with corresponding mapping as below:

public class Customer
{
    public virtual int CustomerId { get; private set; }
    //...
    开发者_开发问答public virtual List<int> Orders { get; set; }
}

public class CustomerMap : ClassMap<Customer>
{
    public CustomerMap()
    {
        Id(x => x.PatientId)
            .GeneratedBy.Native();

        HasMany(x => x.Orders)
            .Element("OrderId", t => t.Type<int>())
            .Table("CustomerOrder")
            .KeyColumn("CustomerId")
            .ForeignKeyConstraintName("FK_Customer_Order")
            .Cascade.All();
    }
}

Assume class Order is in another database, so I can't map it in this assembly. (I'm not sure this is the best way of doing this, please feel free to comment on the mapping too.)

So I would like to be able to find Customers with more than N orders, SQL query would look like this:

select * from Customer c where
    (select count(*) from orders where CutsomerId = c.CustomerId) > N

What would be Criteria API equivalent?


As another option could you not just add an OrderCount property to your Customer class so you don't need the join to the other DB.

Anything you do which joins cross DB or joins to unmapped classes feels a bit wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜