开发者

Add LINQ Auto-Generated Value Marker [Column(IsDbGenerated=true)] in Buddy Class

开发者 https://www.devze.com 2023-01-03 09:55 出处:网络
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(BuddyMet

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号