如何在没有实体框架的情况下实施Odata API?

时间:2016-02-09 14:31:52

标签: asp.net-mvc c#-4.0 odata asp.net-web-api2 ienumerable

我创建了OData Controller,它具有从服务返回数据列表的方法,而不是服务IEnumarable数据。我需要从SQL Query返回IQueryable或IEnurable数据。我在核心逻辑中有简单的SQL Data Adapeter和SQL Command Code结构。

1 个答案:

答案 0 :(得分:0)

  1. 您可以使用linq扩展名.AsQueryable()来转换您的项目集合。

  2. 您还可以在控制器操作中接受let mainArray = [7, 7, 3, 2, 2, 2, 1, 7, 5, 5] var newArray: [[Int]] = [] for var i=0; i < mainArray.count; i++ { let element = mainArray[i] if mainArray.indexOf(element) == i { var subArray = mainArray.filter({ $0 == element }) newArray.append(subArray) } } print(newArray) // -> [[7, 7, 7], [3], [2, 2, 2], [1], [5, 5]] 对象,并解析要在SQL查询中使用的项目。

    <Style  x:Key="ButtontopStyleGroove"
            TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid x:Name="RootGrid" Background="{TemplateBinding Background}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                       Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="transparent" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <PointerUpThemeAnimation Storyboard.TargetName="RootGrid" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <ContentPresenter x:Name="ContentPresenter"
                              BorderBrush="#393185"
                              Content="{TemplateBinding Content}"
                              />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
  3. 可以在http://www.ben-morris.com/parsing-odata-queries-decoupled-data-entities-webapi/

    中找到有关QueryOptions的说明