LINQ to SQL 关联映射
我正在开发一个简单的命令行应用程序来自学一些 C# 中的 LINQ to SQL。我有一个 SQL Server 2008 实例,我试图在 MSDB 中查找 SQL Server 上当前设置的作业。我想输出作业名称一个点和步骤名称以及执行此操作的实际 SQL 语句如下:
use msdb
go
select j.name + '.' + s.step_name
from sysjobs j
join sysjobsteps s on j.job_id = s.job_id
order by j.name
go
我不知道如何在 C# 代码中建立 SysJobs 和 SysJobSteps 之间的关系,并且我不断收到以下信息错误消息:
System.InvalidOperationException: Invalid association mapping for member
'ServerCompare.Lib.Commands.SysJob.SysJobSteps'.
'ServerCompare.Lib.Commands.SysJob' is not an entity.
请告知执行此操作的最佳方法是什么?
I am working on a simple command line app to teach myself some LINQ to SQL in C#. I have a SQL Server 2008 instance and I am trying to look in MSDB for the Jobs currently setup on the SQL Server. I want to output the Job Name a dot and the Step name and the actual SQL statement to do that is the following:
use msdb
go
select j.name + '.' + s.step_name
from sysjobs j
join sysjobsteps s on j.job_id = s.job_id
order by j.name
go
I am at a loss for how to establish the relationship between SysJobs and SysJobSteps in the C# code and I keep getting the following error message:
System.InvalidOperationException: Invalid association mapping for member
'ServerCompare.Lib.Commands.SysJob.SysJobSteps'.
'ServerCompare.Lib.Commands.SysJob' is not an entity.
Please advise what is the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两个表都必须有定义的主键。使用
Column(Name="whatever_id", IsPrimaryKey=true)
Both tables must have a defined primary key. Use
Column(Name="whatever_id", IsPrimaryKey=true)
您需要首先创建一个 dbml 文件,添加这两个表,然后使用类似以下内容:
要使用系统表创建 dbml,您需要先创建一个连接,然后右键单击服务器 -> 。更改视图 ->对象类型,您现在应该看到所有系统表。然后添加两个表。
You need to create a dbml file first, adding those two tables and then use something like this:
To create a dbml with system tables you need to do create a connection first, then right-click the server -> change view -> object type, you should now see all system tables. Then add the two tables.