开发者

Fluent nHibernate some kind of flat table

i have one problem (obviously :) ) Is it possible to make dynamic queries in nHibernate in that way... I have many tables (let we say: User, City, Country, Continet,...) is i开发者_运维技巧t possible to flaten this data so i do not need to know joins between this tables (get continent for user, without making join user.city, city.country, coutry.continent)?

The point is i want to some kind flatten data, so user can dynamically select data on user interface without knowing data model behind application?

It will be great that someone gave me at least idea how to make this, or if it's possible...

One example on web is GoogleAnalytics Custom reports (you can drag dimensions and metrics on UI and get results)


You said you're using Fluent NHibernate, which means that, assuming your domain model is structured correctly, you should not need to use any joins.

"Flattening" the data is a UI concern, not a database concern, so you shouldn't flatten your data model or simplify it for the UI unless you absolutely have to.

Let's assume you have the following entities:

public class User
{
    public virtual string Name { get; set; }
    public virtual City City { get; set; }
}

public class City
{
    public virtual string Name { get; set; }
    public virtual Country { get; set; }
}

public class Country
{
    public virtual string Name { get; set; }
}

If you want to filter users by a certain country, the LINQ query for this (assuming NHibernate 3) would be:

var country = session.Single<Country>(x => x.Name == "Africa");
session.Query<User>().Where(x => x.City.Country == country);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜