简体   繁体   English

Linq2sql和WCF,可以访问表

[英]Linq2sql and WCF, getting access to tables

I'm having some difficulties while using linq2sql and wcf. 使用linq2sql和wcf时遇到一些困难。
Let suppose I have three tables: Reports , Tasks and Types . 假设我有三个表: ReportsTasksTypes 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). Tasks引用Reports (一个Report可以具有无限数量的tasks ), Reports引用TypesReport具有某种类型,例如BugReport,ChangeRequest等)。

Now I want to get by WCF all Reports . 现在我想通过WCF获取所有Reports I've written GetAllReports() function. 我已经编写了GetAllReports()函数。 There was of course problem with getting data related to Reports ( Tasks in this case). 当然,获取与Reports相关的数据存在问题(在本例中为Reports Tasks )。 LoadOptions for dataContext were enough in this case. LoadOptions的DataContext的是足够在这种情况下。
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. 但是现在我遇到了另一个问题:我也想访问Types表,即当我拥有Report对象时,我希望能够从Report所关联的行中获取Type名称或其他名称。 In this case LoadOptions doesn't work. 在这种情况下, LoadOptions不起作用。

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. 调试服务时,返回的值都可以-可以参考Tasks和Types表。 However after transferring object to WCF client, only Tasks table is present, Types are missing. 但是,将对象传输到WCF客户端后,仅存在“任务”表,“类型”丢失。
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). 我注意到,当前仅存在表,该表引用查询的主表(在这种情况下为Report;任务使用报告,因此它们存在),而不是主表使用的那个(在这种情况下为Types; Report)使用“类型”,而“类型”不存在)。

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. 我已经将序列化模式设置为对整个dbml模式都是单向的,我认为它将应用于模式中的所有实体。 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. 我还查看了Mike Chaliy提到的WCF数据服务,但我认为这不是我想要的。 I'm working on university project where I'm supposed to use Linq2Sql over WCF. 我正在研究应该在WCF上使用Linq2Sql的大学项目。

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. 我检查了一下,模式已设置了unidirectional Serialization Mode ,单个表没有序列化模式,所以我看起来一切都设置正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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