Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF数据服务的动态实体模型_C#_Wcf_Dynamic_Wcf Data Services_Odata - Fatal编程技术网

C# WCF数据服务的动态实体模型

C# WCF数据服务的动态实体模型,c#,wcf,dynamic,wcf-data-services,odata,C#,Wcf,Dynamic,Wcf Data Services,Odata,我想使用WCF数据服务将SQL数据库的内容公开为OData提要 只要SQL数据库模式保持不变,一切都可以正常工作。一旦添加了数据库表或更改了数据库表,实体模型就过时了。重新编译数据服务不是一个选项,因为模式一天可以更改几次 我正在定义一个表数据服务: public class TablesDataService { private static List<Table> _tables; static TablesDataService() {

我想使用WCF数据服务将SQL数据库的内容公开为OData提要

只要SQL数据库模式保持不变,一切都可以正常工作。一旦添加了数据库表或更改了数据库表实体模型就过时了。重新编译数据服务不是一个选项,因为模式一天可以更改几次

我正在定义一个表数据服务:

public class TablesDataService
{
    private static List<Table> _tables;

    static TablesDataService()
    {
        _tables = new List<Table>();
        // query the database and add a table entity model for each table
    }

    public IQueryable<Table> Tables
    {
        get { return _tables.AsQueryable<Table>(); }
    }
}
WCF数据服务用于WcfDataService.svc中的以下类:

public class WcfDataService : DataService<TablesDataService>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        config.SetEntitySetAccessRule("Tables", EntitySetRights.All);
    }
}
其中Code是包含美国州代码的char(2)列

到目前为止,任何使用ExpandooObject(而不是Table类)或让Table类派生自DynamicObject的尝试都未能创建可用的OData提要,导致以下“请求错误”:

异常消息为“内部服务器错误”。不支持类型“ServiceLibrary.Table”

堆栈跟踪显示内部抛出的异常

System.Data.Services.Providers.ReflectionServiceProvider.BuildHierarchyForEntityType

有没有办法创建一个公开属性(表示相应数据库表的列)的表类WCF数据服务可以动态地使用它来浏览SQL数据库?

包含R/W非类型数据提供程序的示例实现,可以轻松地修改它以返回元数据和表数据。

您所要求的是可能的,但它是混乱的。首先,您不应该通过web服务传递数据库对象——客户机不需要了解数据库实现。第二,您绝对不应该经常更改数据库模式,尤其是一天不应该更改几次。实际上,客户机并不知道(或关心)对象是如何存储的,模式也不经常更改,但我想指出的是,重新编译不是一个实用的选择。所以现在你取笑我:我该如何解决这个问题?我不怀疑它是一团糟,因为我无法用传统的方法解决它。也许新发布的允许继承的WCF数据服务CTP可以解决这个问题?
http://localhost/WcfDataService.svc/Tables('Population')?$filter=Code eq 'CA'
System.Data.Services.Providers.ReflectionServiceProvider.BuildHierarchyForEntityType