Visual Web Developer 2008 不会自动从 Linq 生成类

发布于 2024-08-07 22:10:29 字数 366 浏览 8 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

递刀给你 2024-08-14 22:10:29

不,你没有错过任何东西。这正是它应该如何工作的。转到解决方案资源管理器,展开 dbml,然后双击whatever.designer.cs。在底部,您会看到……

[Table(Name="dbo.YourTable")]
public partial class YourTable: INotifyPropertyChanging, INotifyPropertyChanged
{

    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

以及您的所有财产。

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 ...

[Table(Name="dbo.YourTable")]
public partial class YourTable: INotifyPropertyChanging, INotifyPropertyChanged
{

    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

... and all of your properties.

梦归所梦 2024-08-14 22:10:29

正如其他回答者已经指出的那样,您确实可以将代码生成到单个 (modelname).designer.cs 文件中。

这可能是也可能不是您所期望和想要的 - 如果您可以忍受它 - 完美!

如果没有,至少有一组名为 PLINQO 的代码生成模板,它基于 CodeSmith,已知的代码生成器。这些模板允许您执行标准 Linq-to-SQL 不支持的许多操作:

  • 为每个表生成类到用户可定义的文件夹中自己的单个文件中,
  • 实际上更新您的 DBML 模型如果底层数据库发生更改,所有关联的生成类
  • 都会添加一个“(entityname)Manager”类来管理给定类型的实体(例如 Customer 等)。

总而言之,这是处理 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:

  • generate classes for each table into their own, single file in a user-definable folder
  • actually update your DBML model and all associated generated classes if the underlying database changes
  • adds a "(entityname)Manager" class to manage entities of a given type (like Customer etc.)

All in all, it's quite a neat solution to handle Linq-to-SQL code generation. Excellent stuff - recommended!

Marc

沐歌 2024-08-14 22:10:29

如前所述,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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文