Visual Web Developer 2008 不会自动从 Linq 生成类
我是 Linq 和 Visual Web Developer 2008 Express 的新手。我读过这里的一些帖子和 Scott Guthrie 的关于设置 Linq 的文章,但我有点困惑,因为这些类并不像我想象的那样自动生成。我设置了一个包含一个简单表(以主键作为 ID,并且设置为自动增量)和其他一些列的数据库,并将其拖放到 DBML Linq 设计器窗格中。该表出现在窗口中,但不会自动生成任何类。当我右键单击表格并选择“查看代码”时,会显示 DataClasses.cs
,但我只看到一个没有方法或属性的部分类。
难道 Linq 不应该这样做吗?还是我(很可能)完全错过了重点?或者 Visual Web Developer 2008 Express 中不提供此功能?
I'm new to Linq and Visual web developer 2008 Express. I have read some posts here and Scott Guthrie's on setting up Linq, but I'm a little stuck because the classes aren't auto-generating as I thought they would. I have setup a database with a simple table (with the Primary Key as the ID, and it is set to auto-increment) plus a few other columns, and dragged and dropped it on to the DBML Linq designer pane. The table appears in the window, but no classes are auto-generated. When I right click on the table and select "View Code", DataClasses.cs
is displayed, but I only see a partial class with no methods or properties.
Isn't Linq supposed to do this, or have I (quite likely) missed the point completely? Or is this functionality not available in Visual Web Developer 2008 Express?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,你没有错过任何东西。这正是它应该如何工作的。转到解决方案资源管理器,展开 dbml,然后双击whatever.designer.cs。在底部,您会看到……
以及您的所有财产。
No, you're not missing anything. That is exactly how it should work. Go to solution explorer, expand the dbml, and double-click on whatever.designer.cs. Down at the bottom, you'll see ...
... and all of your properties.
正如其他回答者已经指出的那样,您确实可以将代码生成到单个 (modelname).designer.cs 文件中。
这可能是也可能不是您所期望和想要的 - 如果您可以忍受它 - 完美!
如果没有,至少有一组名为 PLINQO 的代码生成模板,它基于 CodeSmith,已知的代码生成器。这些模板允许您执行标准 Linq-to-SQL 不支持的许多操作:
总而言之,这是处理 Linq-to-SQL 代码生成的一个非常简洁的解决方案。很棒的东西 - 推荐!
马克
As the other answerers have already pointed out, you do get your code generated - into a single (modelname).designer.cs file.
This may or may not be what you expected and wanted - if you can live with it - perfect!
If not, there's at least one set of Code generation templates out there called PLINQO which are based on CodeSmith, the well known code generator. Those templates allow you to do a lot of things standard Linq-to-SQL doesn't support:
All in all, it's quite a neat solution to handle Linq-to-SQL code generation. Excellent stuff - recommended!
Marc
如前所述,LINQ-To-SQL 实际上不会为您生成单独的类文件 - 如果您编写一些引用其中一个表的类的代码,您会发现它就在那里......
As mentioned, LINQ-To-SQL will not actually generate individual class files for you - if you go and write some code that references a class for one of your tables, you will find that it is there...