简体   繁体   中英

.NET OData Web api

I have 2 ways to use a model generated by Entity Framework. I can not find which to use when and why.

  1. Method 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.

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.

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.

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