Hi
I'm having some difficulties while using linq2sql and wcf.
Let suppose I have three tables: Reports
, Tasks
and Types
. Tasks
references Reports
(one Report
can have unlimited number of tasks
), and Reports
references Types
(Report
is of some type, e.g. BugReport, ChangeRequest and something like that).
Now I want to get by WCF all Reports
. I've written GetAllReports()
function. There was of course problem with getting data related to Reports
(Tasks
in this case). LoadOptions
for dataContext were enough in this case.
But now I have different problem: I want to have access to Types
table too, i.e. when I have Report
object, I want to be able to get Type
name or something, from row Report
is related to. In this case LoadOptions
doesn't work.
Here is my code for getting all reports:
public ICollection<Database.Zgloszenia> GetAllReports()
{
using (var dataContext = new Database.ChangeSystemDataDataContext())
{
var loadOptions = new System.Data.Linq.DataLoadOptions();
loadOptions.LoadWith<Database.Reports>(t => t.Tasks);
loadOptions.LoadWith<Database.Reports>(t => t.Types);
dataContext.LoadOptions = loadOptions;
return dataContext.Reports.Select(r => r).ToList();
}
}
When debugging service, returned value is all ok - there is reference to Tasks and Types tables. However after transferring object to WCF client, only Tasks table is present, Types are missing.
I've noticed, that present are only tables, that reference main table of query (in that case Report; tasks use reports, so they are present), not the one, that are used by main table (in that case Types; Report uses Types, and Types are not present).
Is that default behavior that cannot be changed, or there is some way to include Types row(s) to result of query?
Thanks in advance
Jarek