Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to SQL Association Mapping

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?

like image 958
λ Jonas Gorauskas Avatar asked Apr 28 '11 20:04

λ Jonas Gorauskas


1 Answers

Both tables must have a defined primary key. Use Column(Name="whatever_id", IsPrimaryKey=true)

like image 72
Craig Stuntz Avatar answered Sep 19 '22 06:09

Craig Stuntz