开发者

Is any way in fluent NH to map Views?

Is any way in fluent NH to map [View]s to c# classes? I开发者_StackOverflow社区 need to have them read-only.


NHibernate allows you to map views as you would a table. It's exactly the same. The only thing you can't do is update it.


NHibernate does not know if the object you specify as "table" is actually a table or a view.

If you're not going to write to them, there's nothing to worry about.


As explained in the other answers you can map a view exactly the same way as a table. I would configure them read-only in order to have non-allowed inserts caught in your application and not returned as error from the database:

public class MyViewMapping : ClassMap<MyViewType>
{
    public MyViewMapping()
    {
        Table("VIEW_NAME");

        ReadOnly();

        // Add all view fields here...
        Map(x => x.Field1, "Field1Name");
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜