Adding more attributes to LINQ to SQL entity

2019-08-23 05:39发布

I want to add browsable attribute to some properties for entities generated by LINQ to SQL.

Is it a good idea? Since these entities are auto-generated, and when I regenerate they (the attributes I have added) might be overwritten.

标签: linq-to-sql
2条回答
你好瞎i
2楼-- · 2019-08-23 06:12

You cannot add additional attributes to the properties in another partial class file because you would be defining the property more than once. This is one reason, among others, that we created our own code generator that generates L2S entity classes the way we want them.

Our code generator also generates a second set of 'application' entities that are much more lightweight than the L2S entities and used at the application level. They contain no L2S plumbing, but do contain other characteristics that the application level finds useful.

查看更多
迷人小祖宗
3楼-- · 2019-08-23 06:17

I would probably use Damien Guards LINQ to SQL T4 templates, and modify the template to include the attributes you need. Then the attributes will be generated when you regenerate the classes.

查看更多
登录 后发表回答