简体   繁体   English

.NET OData Web API

[英].NET OData Web api

I have 2 ways to use a model generated by Entity Framework. 我有2种方法来使用实体框架生成的模型。 I can not find which to use when and why. 我找不到何时何地使用哪个。

  1. Method 1 方法1

      ODataQueryOptions<Key_Result> options (Passed as function argument) private ODataQuerySettings settings = new ODataQuerySettings(); IQueryable<Key_Result> result; try { result = options.ApplyTo(DataAccessFunction.Key(keyIds), settings) as IQueryable<Key_Result>; } 
  2. Method 2 方法二

      IQueryable<Log> result; try { result = AccessModel.Log; } 

So far, I have used them in my code without knowing what is correct or why both are even used. 到目前为止,我已经在代码中使用了它们,却不知道什么是正确的或者为什么甚至都使用了它们。 I can't find any material to help me too. 我也找不到任何可以帮助我的材料。

Also, the first one I am using in Odata endpoints created using the table valued functions in sql while the second one I am using with endpoints created using simple tables and views. 另外,我在Odata端点中使用的第一个是使用sql中的表值函数创建的,而第二个我是在使用简单表和视图创建的端点中使用的。

But if Entity framework is consistent, it shouldn't matter. 但是,如果实体框架是一致的,那就没关系了。 And I should be able to use the two approaches interchangeably. 而且我应该能够交替使用这两种方法。 Can they be used interchangeably, what is the difference which makes them preferred for one situation (Table valued function) and not preferred for the other one (Tables, views). 它们可以互换使用吗?有什么区别,使它们更适合一种情况(表值函数),而不适合另一种情况(表,视图)。

Both can be used but both have different uses. 两者都可以使用,但是用途不同。 If my settings parameters such as null propagation, stable sort or page size have to be set I could use method 1. 如果必须设置诸如空传播,稳定排序或页面大小之类的设置参数,则可以使用方法1。

However, setting page size etc. could also be done without this. 但是,也可以不设置页面大小等。 Method 2 is the simplest but does not handle any page sizing or null propagation etc. 方法2是最简单的方法,但不处理任何页面大小调整或null传播等。

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

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