使用HNibernate中的代码映射来忽略列 [英] Ignore column using mapping by code in HNibernate

查看:86
本文介绍了使用HNibernate中的代码映射来忽略列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NHibernate中的代码映射. 我上了一堂课,有几个属性.其中之一与数据库中的任何列无关,但仍然具有getter和setter.

I'm using mapping by code in NHibernate. I got a class with several properties. One of them is not related to any columns in DB but still has getter and setter.

我使用ConventionModelMapper而不是ModelMapper.第一个假设所有属性都已映射.

I use ConventionModelMapper not ModelMapper. The first one assumes that all properties are mapped.

我如何告诉NHibernate忽略它?

How i can tell to NHibernate to ignore it?

推荐答案

为什么不映射所需的属性,而保留不需要映射的属性

Why not map the properties you want and leave the ones not needed to be mapped

检查您可以按以下方式管理ConventionModelMapper的持久性:

You can manage the persistence of ConventionModelMapper as following:

mapper.BeforeMapProperty += (mi, propertyPath, map) =>
{
    // Your code here using mi, propertyPath, and map to decide if you want to skip the property .. can check for property name and entity name if you want to ignore it
};

一个更好的答案是:

mapper.IsPersistentProperty((mi, declared) =>
                                             {
                                                 if (mi.DeclaringType == typeof (YourType) && mi.Name == "PropertyNameToIgnore")
                                                     return false;
                                                 return true;
                                             });

这篇关于使用HNibernate中的代码映射来忽略列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆