如何在 LINQ To SQL 上装饰自定义成员
我想在 LINQ To SQL 设计器生成的类上创建一个属性,用于获取和设置格式化类型,如下所示:
public partial ALinqClass
{
public string formatedValue
{
get { return formatValue(TheValue); }
set { TheValue = RemoveFormating(value); }
}
}
TheValue 是 Linq 设计器生成的属性。
如何装饰 public string formatedValue
以便将其绑定到表单上的控件? 例如:当我使用 Visual Studio 从 linq 对象/类创建对象数据源时,linq 生成的所有属性都出现在对象数据源上,但 formatedValue 则不然。
为什么 ?
为什么 ?
哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈)
谢谢。
法比奥
I want to create a property on my LINQ To SQL designer-generated class that gets and sets a formatted type, like that:
public partial ALinqClass
{
public string formatedValue
{
get { return formatValue(TheValue); }
set { TheValue = RemoveFormating(value); }
}
}
TheValue is the property generated by the Linq designer.
How do I decorate public string formatedValue
so I can bind it to controls on my form?
For example: When I use Visual Studio to create a Object Data Source from my linq object/class all properties linq generated are present on the Object data Source, but formatedValue is not.
Why ?
WHY ?
WHHHHHHHHY ????????!!!!!
Thank you.
Fábio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Linq-to-SQL 生成的实体被声明为分部类,因此您应该能够创建另一个文件并向同一分部类添加自定义属性。这样,如果您必须重新生成类,您对实体的添加仍然可以在不同的文件中使用。
此外,只要这些属性是公共的,您就应该能够像生成的属性一样对它们进行数据绑定。
Linq-to-SQL generated entities are declared as partial classes so you should be able to create another file and add custom properties to the same partial class. This is so if you have to regenerate the classes, your additions to the entities are still available in a different file.
Also as long as these properties are public, you should be able to databind them just like generated properties.
对于 Windows 窗体数据绑定,您需要
从
Control
派生的数据源。中间组件
BindingSource
,充当 LinqToSql 数据源和绑定控件之间的链接。我将概述如何使用
BindingSource
。显然,这个简短的示例并不完整,但应该可以让您了解如何开始。更多信息请访问数据绑定和 Windows 窗体< /a>.
标记
For Windows Forms Databinding, you need either
A datasource, which is derived from
Control
.An intermediate component,
BindingSource
, acting as link between the LinqToSql datasource and bound controls.I'll outline how to use
BindingSource
.Obviously, this short sample is not complete, but should give you an idea on how to start. Further information can be found at Data Binding and Windows Forms.
Mark
我想这就是我想要的答案。 Linq 必须有更多的类和继承,但我认为这样就可以了。
http://msdn.microsoft.com/en-us/library /system.componentmodel.bindableattribute.aspx
I think this is the answer I wanted. Linq must have a few more classes and inheritances, but I think this will do.
http://msdn.microsoft.com/en-us/library/system.componentmodel.bindableattribute.aspx