在 Buddy 类中添加 LINQ 自动生成的值标记 [Column(IsDbGenerate=true)]
是否可以使用buddy class(通过链接到LINQ类>[MetadataType(typeof(BuddyMetadata))]
) ?
我的目标是能够清除并重新填充 LINQ ORM 设计器,而不必每次都手动设置“自动生成值”属性来重新确定某些列是自动生成的这一事实。
谢谢!
is it possible to decorate a field of a LINQ generated class with [Column(IsDbGenerated=true)]
using a buddy class (which is linked to the LINQ class via [MetadataType(typeof(BuddyMetadata))]
) ?
My goal is to be able to clear and repopulate the LINQ ORM designer without having to set the "Auto Generate Value" property manually every time to re-establish the fact that certain columns are autogenerated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
LINQ to SQL 无法识别伙伴类。
您不能只将属性添加到部分,因为该属性已经在另一个部分中定义(这就是发明伙伴类来解决的问题)。
一种选择是使用我的 VS 的 T4 模板,它复制 LINQ to SQL 的代码生成功能(我曾经在产品团队工作过),您可以在其中放置一些逻辑来检测自动生成的列并发出每次都正确的属性。
http://l2st4.codeplex.com
LINQ to SQL does not recognize buddy classes.
You can't just add the attribute to the partial either as the property is already defined in the other partial (this is what buddy classes were invented to solve).
One option would be to use my T4 template for VS that replicates the code-generation functionality of LINQ to SQL (I used to work on the product team) and you could put some logic in there to detect your auto-generated columns and emit the right attribute every time.
http://l2st4.codeplex.com
您可以使用 部分类 - 使用您自己的部分类并装饰它与属性。它将免受代码生成的影响。
如果需要修饰方法,可以使用部分方法 也是如此。
据我所知,如果代码生成器在重新生成时不破坏字段,则无法以这种方式装饰字段。
You can use a partial class - use your own partial class and decorate it with the attribute. It will be safe from the code generation.
If you need to decorate a method, you may be able to use partial methods as well.
As far as I know, fields cannot be decorated this way without the code generator destroying them on re-generation.