您可以阻止 LinqDataSource 设置属性吗?
我有一个正在尝试更新的 Linq 2 SQL 对象。 该对象的两个属性彼此相关,设置一个属性会设置另一个属性。
所以如果我这样做:
Foo.Code = BEER;
Foo.CodeID 属性将自动设置为 5(或其他值)。
问题是 LinqDataSource 设置 Foo.Code,然后立即设置 Foo.CodeID...它不绑定到任何内容,因为我们希望用户只设置 Code 。 这立即将它们都设置回空。
我知道我可以使用参数作为默认值,但是有什么方法可以告诉 LinqDataSource 甚至不设置属性吗?
编辑:通过创建隐藏字段并为表单视图的 ItemUpdating 事件中的值分配正确的值来解决问题。 但仍然希望避免四次进行相同的查找......
I've got a Linq 2 SQL object I'm trying to update. Two of the properties on this object are related to each other, and setting one sets the other.
So if I do:
Foo.Code = BEER;
The Foo.CodeID property will automatically be set to 5 (or whatever.)
The problem is that LinqDataSource sets Foo.Code, then immediately sets Foo.CodeID... which is not bound to anything since we want the users to set just Code. This immediately sets them both back to null.
I know I can use Parameters to default values, but is there any way to just tell LinqDataSource to not even set a property?
EDIT: Worked around issue by creating a hidden field, and assigning the correct value to that in the formview's ItemUpdating event. Would still like to avoid doing the same lookup four times though...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否可以选择将 Code 属性设置为私有(在 dbml 中选择 Code 属性并在“属性”窗口中设置访问属性)并创建一个新的公共属性(您可以对其进行更多控制)?
我个人编写了一个生成器,可以为我生成必要的文件(如 sqlmetal),使我可以完全控制代码。 如果您不喜欢生成的 dbml,也许这也是您的一个选择。
Would it be an option to make the Code property private (select the Code property in the dbml and set the access property in the Properties window) and create a new public property over which you have more control?
I personally have have written a generator that generates the necessary files for me (like sqlmetal), giving me full control over the code. Perhaps this is an option for you as well, if you do not like the generated dbml.