views:

76

answers:

3

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

A: 

Not exactly answer to your question, but have you seen WCF Data Services?

Mike Chaliy
A: 

Have you set the serialization mode on each of your entity classes to Unidirectional in the LINQ to SQL designer?

nitzmahone
A: 

I've set serialization mode to unidirectional to whole dbml schema, I thought that it will be applied to all entities in schema. And I think it is, serializing entities works good.
I will check it once more at home.

I also looked at WCF Data Services, that Mike Chaliy mentioned, but I think that's not what I'm looking for. I'm working on university project where I'm supposed to use Linq2Sql over WCF.

Edit:
I checked, schema have unidirectional Serialization Mode set on, single table does not have serialization mode, so I looks like everything is set ok.

Pako