简体   繁体   中英

Linq2sql and WCF, getting access to tables

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, eg 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, ie 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

不能完全回答您的问题,但是您看到过WCF数据服务吗?

您是否已在LINQ to SQL设计器中将每个实体类的序列化模式设置为“单向”?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM