LINQ to SQL的 - 保存之前格式化字符串? [英] LINQ to SQL - Format a string before saving?

查看:244
本文介绍了LINQ to SQL的 - 保存之前格式化字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想现有的(非的LINQ to SQL)类转换成具有现有(DB列),如属性的LINQ to SQL实体类:

I'm trying to convert an existing (non-LINQ to SQL) class into a LINQ to SQL entity class which has an existing (db column) property like:

public string MyString
{
    get { return myString; }
    set { myString = FormatMyString(value); }
}



有没有办法做这样的处理对在保存之前的实体类属性的值?

我应该使用某种形式在做我的格式实体层面节省事件的(如果将连工作)?

Should I use some sort of an entity-level saving event in which to do my formatting (if that will even work)?

我知道的LINQ to SQL提供验证和有产生在...改变()部分它提供了进入新的价值,的方法,通过值(不是REF)的,但没有这些方法似乎提供了一种实际修改/格式化值 当正在设置。

I know LINQ to SQL provides validation and there are generated On...Changing() partial methods which provide access to the new value, by value (not by ref), but none of those methods seem to provide a way to actually modify/format the value while it is being set.

感谢您的帮助。

推荐答案

怎么样使用On ...()改变?它触发属性值更改后。在那里,你可以检查它的价值和使用的formatString更新它。

What about using On...Changed()? It fires after the property value has changed. There you can check its value and update it using the FormatString.

这篇关于LINQ to SQL的 - 保存之前格式化字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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