开发者

How to specify to NOT map an object Property in MongoDB with NORM

开发者 https://www.devze.com 2023-01-04 10:35 出处:网络
I have a calculated property in my object that I don\'t want to save to the DB, is there a way I can specify that?

I have a calculated property in my object that I don't want to save to the DB, is there a way I can specify that?

Like this one as an exemple :

public virtual string 开发者_如何转开发FullInfos
    {
        get
        {
            var html = Contact1Info;
            html += Contact2Info;
            return html;
        }
    }

Where Contact1Info and Contact2Info are automatic property already saved...

Thanks!


NoRM provides a series of attributes. In this case you're looking for the [MongoIgnore] attribute.

Should be as simple as

[MongoIgnore]
public virtual string FullInfos
    {
        get
        {
            var html = Contact1Info;
            html += Contact2Info;
            return html;
        }
    }


Convert it to a method, in which case NORM won't map it.

These kinds of "Properties" are better defined as methods anyways.. in the strict OO sense it shouldn't be viewed as a "Property" of the object if it is being calculated.

0

精彩评论

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