从存储过程生成信息(包装)类
我正在进行一个关键项目,我试图通过使用 Codesmith 为我的项目表生成业务类 DAL 和信息类来加快开发阶段。
大约有 50 个表,其父子关系为多对多,为了检索数据,我必须在存储过程中编写几个内部联接。 我必须组合许多表中的字段,这使得使用信息类变得困难。
无论如何,是否有从存储过程生成信息类,或者更准确地说,是否有一种方法可以解析存储过程的结果集并生成具有该结果集中每一列的属性的信息类。
如果有人能给我一些建议并告诉我如何实现这一目标,请告诉我。 此致
I am in a crucial project and I am trying to speed up the development phase by using codesmith for generating the business class DAL and info class for the tables of my project.
There are about 50 tables with relationships parent child many to many and for retrieving data I have to code several inner joins in stored procedures.
I have to combine fields from many tables and this makes working with the info class difficult.
Is there anyway to generate info class from stored procedures or to be more exact is there a way to parse the result set of the stored procedure and to generate the info class with properties for every column in that result set.
Please if anyone can give me some advice and tell me how to achieve this.
Best Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用基于通过 SchemaExplorer.CommandSchema 集合公开的存储过程的模板轻松生成代码。有人写了一篇关于如何开始的有用博客文章 - http:// /jianningtang.spaces.live.com/blog/cns!90A00B80F75CB859!210.entry。
You can easily generate code using templates based on stored procs which are exposed via the SchemaExplorer.CommandSchema collection. Somebody has written a helpful blog post about how to get started - http://jiangningtang.spaces.live.com/blog/cns!90A00B80F75CB859!210.entry.
我曾经做过的一个技巧 - 现在我不再使用 CodeSmith - 是用信息类中我想要的字段创建一个视图或假表。将 CodeSmith 指向它并从中生成一个类。
另一种方法是避免使用信息类和一些自定义业务对象并构建自己的数据层 - 有时在复杂的项目中这更容易。
One trick I used to do - and I dont use CodeSmith anymore - was to make a view or fake table with the fields I want in the info class. Point CodeSmith at it and generate a class from that.
Another way to sort of get by is to avoid the info class and some of the custom business objects and build you own data layer - sometimes in complex projects this is easier.
我还有另一个建议,创建一个类库并向其中添加一个数据集(数据部分中可用的类型化数据集或添加新项目),将所有 SP 和表放入数据上下文中,然后从设计器复制 cs 代码;)
我希望这会对你有帮助。
I have another suggestion, Create a class library and add a DataSet (Typed Data set available in Data section or add new item) to it, drop all your SPs and tables in the data context and copy the cs code from designer ;)
i hope this will help you.