您可以阻止LinqDataSource设置属性吗? [英] Can you prevent LinqDataSource from setting a property?

查看:81
本文介绍了您可以阻止LinqDataSource设置属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要更新的Linq 2 SQL对象.此对象上的两个属性彼此相关,设置一个属性会设置另一个属性.

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.

所以,如果我这样做:

Foo.Code = BEER;

Foo.Code = BEER;

Foo.CodeID属性将自动设置为5(或其他值)

The Foo.CodeID property will automatically be set to 5 (or whatever.)

问题是LinqDataSource设置了Foo.Code,然后立即设置了Foo.CodeID ...,由于我们希望用户仅设置Code,因此它没有任何绑定.这将立即将它们都设置为null.

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.

我知道我可以将Parameters用作默认值,但是有什么方法可以告诉LinqDataSource甚至不设置属性?

I know I can use Parameters to default values, but is there any way to just tell LinqDataSource to not even set a property?

通过创建一个隐藏字段并为Formview的ItemUpdating事件中的值分配正确的值来解决此问题.仍然希望避免四次执行相同的查找...

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...

推荐答案

是否可以选择将Code属性设为私有(在dbml中选择Code属性,然后在Properties窗口中设置access属性)并创建一个新的您拥有更多控制权的公共财产?

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?

我个人已经编写了一个生成器,可以为我生成必要的文件(例如sqlmetal),从而使我可以完全控制代码.如果您不喜欢生成的dbml,也许这也是您的一个选择.

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.

这篇关于您可以阻止LinqDataSource设置属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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