|
1 | | -# comminity-odata-linq |
| 1 | +# Community.OData.Linq |
2 | 2 | Use text (OData format) expressons in LINQ methods for any IQuerable |
3 | | -# build status |
4 | | -[](https://ci.appveyor.com/project/IharYakimush/comminity-data-odata-linq/branch/develop) |
5 | 3 |
|
| 4 | +# Sample |
| 5 | +Please check simple code below to get started |
| 6 | +``` |
| 7 | + using System; |
| 8 | + using System.Linq; |
| 9 | + using Community.OData.Linq; |
| 10 | +
|
| 11 | + public class Sample |
| 12 | + { |
| 13 | + public int Id { get; set; } |
| 14 | +
|
| 15 | + public string Name { get; set; } |
| 16 | + } |
| 17 | +
|
| 18 | + public class Demo |
| 19 | + { |
| 20 | + public void SimpleFilter() |
| 21 | + { |
| 22 | + IQueryable<Sample> dataSet = this.CreateQuerable(); |
| 23 | + Sample[] filterResult = dataSet.OData().Filter("Id eq 2 or Name eq 'name3'").ToArray(); |
| 24 | +
|
| 25 | + // Id:2 Name:name2 |
| 26 | + // Id:3 Name:name3 |
| 27 | + foreach (Sample sample in filterResult) |
| 28 | + { |
| 29 | + Console.WriteLine(string.Format("Id:{0} Name:{1}", sample.Id, sample.Name)); |
| 30 | + } |
| 31 | + } |
6 | 32 |
|
7 | | -# nuget |
| 33 | + public void SimpleOrderBy() |
| 34 | + { |
| 35 | + IQueryable<Sample> dataSet = this.CreateQuerable(); |
| 36 | + Sample[] filterResult = dataSet.OData().OrderBy("Id desc").ToArray(); |
| 37 | +
|
| 38 | + // Id:3 Name:name3 |
| 39 | + // Id:2 Name:name2 |
| 40 | + // Id:1 Name:name1 |
| 41 | + foreach (Sample sample in filterResult) |
| 42 | + { |
| 43 | + Console.WriteLine(string.Format("Id:{0} Name:{1}", sample.Id, sample.Name)); |
| 44 | + } |
| 45 | + } |
| 46 | +
|
| 47 | + private IQueryable<Sample> CreateQuerable() |
| 48 | + { |
| 49 | + return new[] |
| 50 | + { |
| 51 | + new Sample { Id = 1, Name = "name1" }, |
| 52 | + new Sample { Id = 2, Name = "name2" }, |
| 53 | + new Sample { Id = 3, Name = "name3" }, |
| 54 | + }.AsQueryable(); |
| 55 | + } |
| 56 | + } |
| 57 | +``` |
| 58 | +# Nuget |
| 59 | +https://www.nuget.org/packages/Community.OData.Linq |
| 60 | + |
| 61 | +# Build Status |
| 62 | +[](https://ci.appveyor.com/project/IharYakimush/comminity-data-odata-linq/branch/develop) |
0 commit comments