├── .gitattributes ├── .github └── workflows │ └── vale.yml ├── .gitignore ├── CS ├── ODataService.sln ├── ODataService │ ├── App_Start │ │ └── WebApiConfig.cs │ ├── Controllers │ │ ├── ActionsController.cs │ │ ├── BaseDocumentController.cs │ │ ├── ContractController.cs │ │ ├── CustomerController.cs │ │ ├── OrderController.cs │ │ ├── OrderDetailController.cs │ │ └── ProductController.cs │ ├── Global.asax │ ├── Global.asax.cs │ ├── Helpers │ │ ├── ApiHelper.cs │ │ ├── ConnectionHelper.cs │ │ ├── DemoDataHelper.cs │ │ └── UriHelper.cs │ ├── Models │ │ ├── BaseDocument.cs │ │ ├── Contracts.cs │ │ ├── Customers.cs │ │ ├── OrderDetail.cs │ │ ├── OrderStatus.cs │ │ ├── Orders.cs │ │ └── Products.cs │ ├── ODataService.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Web.Debug.config │ ├── Web.Release.config │ └── Web.config └── Tests │ ├── ActionTests.cs │ ├── CRUDTests.cs │ ├── Connected Services │ └── ODataService │ │ ├── ConnectedService.json │ │ └── Reference.cs │ ├── GetDataTests.cs │ ├── ODataTestsBase.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── Tests.csproj ├── LICENSE ├── config.json └── readme.md /.gitattributes: -------------------------------------------------------------------------------- 1 | VB/* linguist-vendored 2 | scripts linguist-vendored 3 | *.css linguist-detectable=false 4 | *.aff linguist-detectable=false 5 | -------------------------------------------------------------------------------- /.github/workflows/vale.yml: -------------------------------------------------------------------------------- 1 | name: vale-validation 2 | on: 3 | pull_request: 4 | paths: 5 | - README.md 6 | - readme.md 7 | - Readme.md 8 | 9 | jobs: 10 | vale: 11 | name: runner / vale 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: clone repo 15 | uses: actions/checkout@v4 16 | - name: clone vale-styles repo 17 | uses: actions/checkout@v4 18 | with: 19 | repository: DevExpress/vale-styles 20 | path: vale-styles 21 | ssh-key: ${{ secrets.VALE_STYLES_ACCESS_KEY }} 22 | - name: copy vale rules to the root repo 23 | run: shopt -s dotglob && cp -r ./vale-styles/vale/* . 24 | - name: vale linter check 25 | uses: DevExpress/vale-action@reviewdog 26 | with: 27 | files: '["README.md", "readme.md", "Readme.md"]' 28 | fail_on_error: true 29 | filter_mode: nofilter 30 | reporter: github-check 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # Benchmark Results 46 | BenchmarkDotNet.Artifacts/ 47 | 48 | # .NET Core 49 | project.lock.json 50 | project.fragment.lock.json 51 | artifacts/ 52 | **/Properties/launchSettings.json 53 | 54 | *_i.c 55 | *_p.c 56 | *_i.h 57 | *.ilk 58 | *.meta 59 | *.obj 60 | *.pch 61 | *.pdb 62 | *.pgc 63 | *.pgd 64 | *.rsp 65 | *.sbr 66 | *.tlb 67 | *.tli 68 | *.tlh 69 | *.tmp 70 | *.tmp_proj 71 | *.log 72 | *.vspscc 73 | *.vssscc 74 | .builds 75 | *.pidb 76 | *.svclog 77 | *.scc 78 | 79 | # Chutzpah Test files 80 | _Chutzpah* 81 | 82 | # Visual C++ cache files 83 | ipch/ 84 | *.aps 85 | *.ncb 86 | *.opendb 87 | *.opensdf 88 | *.sdf 89 | *.cachefile 90 | *.VC.db 91 | *.VC.VC.opendb 92 | 93 | # Visual Studio profiler 94 | *.psess 95 | *.vsp 96 | *.vspx 97 | *.sap 98 | 99 | # TFS 2012 Local Workspace 100 | $tf/ 101 | 102 | # Guidance Automation Toolkit 103 | *.gpState 104 | 105 | # ReSharper is a .NET coding add-in 106 | _ReSharper*/ 107 | *.[Rr]e[Ss]harper 108 | *.DotSettings.user 109 | 110 | # JustCode is a .NET coding add-in 111 | .JustCode 112 | 113 | # TeamCity is a build add-in 114 | _TeamCity* 115 | 116 | # DotCover is a Code Coverage Tool 117 | *.dotCover 118 | 119 | # AxoCover is a Code Coverage Tool 120 | .axoCover/* 121 | !.axoCover/settings.json 122 | 123 | # Visual Studio code coverage results 124 | *.coverage 125 | *.coveragexml 126 | 127 | # NCrunch 128 | _NCrunch_* 129 | .*crunch*.local.xml 130 | nCrunchTemp_* 131 | 132 | # MightyMoose 133 | *.mm.* 134 | AutoTest.Net/ 135 | 136 | # Web workbench (sass) 137 | .sass-cache/ 138 | 139 | # Installshield output folder 140 | [Ee]xpress/ 141 | 142 | # DocProject is a documentation generator add-in 143 | DocProject/buildhelp/ 144 | DocProject/Help/*.HxT 145 | DocProject/Help/*.HxC 146 | DocProject/Help/*.hhc 147 | DocProject/Help/*.hhk 148 | DocProject/Help/*.hhp 149 | DocProject/Help/Html2 150 | DocProject/Help/html 151 | 152 | # Click-Once directory 153 | publish/ 154 | 155 | # Publish Web Output 156 | *.[Pp]ublish.xml 157 | *.azurePubxml 158 | # Note: Comment the next line if you want to checkin your web deploy settings, 159 | # but database connection strings (with potential passwords) will be unencrypted 160 | *.pubxml 161 | *.publishproj 162 | 163 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 164 | # checkin your Azure Web App publish settings, but sensitive information contained 165 | # in these scripts will be unencrypted 166 | PublishScripts/ 167 | 168 | # NuGet Packages 169 | *.nupkg 170 | # The packages folder can be ignored because of Package Restore 171 | **/packages/* 172 | # except build/, which is used as an MSBuild target. 173 | !**/packages/build/ 174 | # Uncomment if necessary however generally it will be regenerated when needed 175 | #!**/packages/repositories.config 176 | # NuGet v3's project.json files produces more ignorable files 177 | *.nuget.props 178 | *.nuget.targets 179 | 180 | # Microsoft Azure Build Output 181 | csx/ 182 | *.build.csdef 183 | 184 | # Microsoft Azure Emulator 185 | ecf/ 186 | rcf/ 187 | 188 | # Windows Store app package directories and files 189 | AppPackages/ 190 | BundleArtifacts/ 191 | Package.StoreAssociation.xml 192 | _pkginfo.txt 193 | *.appx 194 | 195 | # Visual Studio cache files 196 | # files ending in .cache can be ignored 197 | *.[Cc]ache 198 | # but keep track of directories ending in .cache 199 | !*.[Cc]ache/ 200 | 201 | # Others 202 | ClientBin/ 203 | ~$* 204 | *~ 205 | *.dbmdl 206 | *.dbproj.schemaview 207 | *.jfm 208 | *.pfx 209 | *.publishsettings 210 | orleans.codegen.cs 211 | 212 | # Since there are multiple workflows, uncomment next line to ignore bower_components 213 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 214 | #bower_components/ 215 | 216 | # RIA/Silverlight projects 217 | Generated_Code/ 218 | 219 | # Backup & report files from converting an old project file 220 | # to a newer Visual Studio version. Backup files are not needed, 221 | # because we have git ;-) 222 | _UpgradeReport_Files/ 223 | Backup*/ 224 | UpgradeLog*.XML 225 | UpgradeLog*.htm 226 | 227 | # SQL Server files 228 | *.mdf 229 | *.ldf 230 | *.ndf 231 | 232 | # Business Intelligence projects 233 | *.rdl.data 234 | *.bim.layout 235 | *.bim_*.settings 236 | 237 | # Microsoft Fakes 238 | FakesAssemblies/ 239 | 240 | # GhostDoc plugin setting file 241 | *.GhostDoc.xml 242 | 243 | # Node.js Tools for Visual Studio 244 | .ntvs_analysis.dat 245 | node_modules/ 246 | 247 | # Typescript v1 declaration files 248 | typings/ 249 | 250 | # Visual Studio 6 build log 251 | *.plg 252 | 253 | # Visual Studio 6 workspace options file 254 | *.opt 255 | 256 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 257 | *.vbw 258 | 259 | # Visual Studio LightSwitch build output 260 | **/*.HTMLClient/GeneratedArtifacts 261 | **/*.DesktopClient/GeneratedArtifacts 262 | **/*.DesktopClient/ModelManifest.xml 263 | **/*.Server/GeneratedArtifacts 264 | **/*.Server/ModelManifest.xml 265 | _Pvt_Extensions 266 | 267 | # Paket dependency manager 268 | .paket/paket.exe 269 | paket-files/ 270 | 271 | # FAKE - F# Make 272 | .fake/ 273 | 274 | # JetBrains Rider 275 | .idea/ 276 | *.sln.iml 277 | 278 | # CodeRush 279 | .cr/ 280 | 281 | # Python Tools for Visual Studio (PTVS) 282 | __pycache__/ 283 | *.pyc 284 | 285 | # Cake - Uncomment if you are using it 286 | # tools/** 287 | # !tools/packages.config 288 | 289 | # Tabs Studio 290 | *.tss 291 | 292 | # Telerik's JustMock configuration file 293 | *.jmconfig 294 | 295 | # BizTalk build output 296 | *.btp.cs 297 | *.btm.cs 298 | *.odx.cs 299 | *.xsd.cs 300 | 301 | #ExampleRangeTester artifacts 302 | TesterMetadata.xml 303 | 304 | # License files 305 | *.licx 306 | 307 | # Backup files 308 | .bak 309 | -------------------------------------------------------------------------------- /CS/ODataService.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2026 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODataService", "ODataService\ODataService.csproj", "{0B2F5AAD-834C-4E16-8FA5-22644CF82973}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{2D5BF66B-FB41-49DD-8E4C-C97648CF159B}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0B2F5AAD-834C-4E16-8FA5-22644CF82973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {0B2F5AAD-834C-4E16-8FA5-22644CF82973}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {0B2F5AAD-834C-4E16-8FA5-22644CF82973}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {0B2F5AAD-834C-4E16-8FA5-22644CF82973}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {2D5BF66B-FB41-49DD-8E4C-C97648CF159B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {2D5BF66B-FB41-49DD-8E4C-C97648CF159B}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {2D5BF66B-FB41-49DD-8E4C-C97648CF159B}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {2D5BF66B-FB41-49DD-8E4C-C97648CF159B}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {F603927E-2886-479E-9E3E-816132A2781C} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /CS/ODataService/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Web.Http; 4 | using WebApplication1.Models; 5 | using Microsoft.AspNet.OData.Batch; 6 | using Microsoft.AspNet.OData.Extensions; 7 | using Microsoft.AspNet.OData.Builder; 8 | using DevExpress.Xpo.Metadata; 9 | using ODataService.Helpers; 10 | using DevExpress.Xpo; 11 | using DevExpress.Data.Filtering; 12 | 13 | namespace WebApplication1 14 | { 15 | public static class WebApiConfig { 16 | public static void Register(HttpConfiguration config) { 17 | config.Count().Filter().OrderBy().Expand().Select().MaxTop(null); 18 | ODataModelBuilder modelBuilder = CreateODataModelBuilder(); 19 | 20 | ODataBatchHandler batchHandler = 21 | new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer); 22 | 23 | config.MapODataServiceRoute( 24 | routeName: "ODataRoute", 25 | routePrefix: null, 26 | model: modelBuilder.GetEdmModel(), 27 | batchHandler: batchHandler); 28 | } 29 | 30 | static ODataModelBuilder CreateODataModelBuilder() { 31 | ODataModelBuilder builder = new ODataConventionModelBuilder(); 32 | 33 | // Approach 1: Automatically add all persistent classes to EDM 34 | // This approach has a naming convention: an OData controller 35 | // name must match the corresponding XPO class name 36 | 37 | var dictionary = new ReflectionDictionary(); 38 | foreach(var type in ConnectionHelper.GetPersistentTypes()) { 39 | XPClassInfo classInfo = dictionary.GetClassInfo(type); 40 | CreateEntitySet(classInfo, builder); 41 | } 42 | 43 | // Approach 2: Manually add persistent classes to EDM 44 | 45 | /*var documents = builder.EntitySet("BaseDocument"); 46 | var customers = builder.EntitySet("Customer"); 47 | var orders = builder.EntitySet("Order"); 48 | var contracts = builder.EntitySet("Contract"); 49 | var products = builder.EntitySet("Product"); 50 | var orderDetails = builder.EntitySet("OrderDetail"); 51 | documents.EntityType.HasKey(t => t.ID); 52 | customers.EntityType.HasKey(t => t.CustomerID); 53 | products.EntityType.HasKey(t => t.ProductID); 54 | orderDetails.EntityType.HasKey(t => t.OrderDetailID); 55 | orders.EntityType.DerivesFrom(); 56 | contracts.EntityType.DerivesFrom();*/ 57 | 58 | // Add actions and functions to EDM 59 | 60 | builder.Action("InitializeDatabase"); 61 | builder.Function("TotalSalesByYear") 62 | .Returns() 63 | .Parameter("year"); 64 | 65 | return builder; 66 | } 67 | 68 | static EntitySetConfiguration CreateEntitySet(XPClassInfo classInfo, ODataModelBuilder builder) { 69 | EntitySetConfiguration entitySetConfig = builder.EntitySets.FirstOrDefault(t => t.EntityType.ClrType == classInfo.ClassType); 70 | if(entitySetConfig != null) { 71 | return entitySetConfig; 72 | } 73 | EntityTypeConfiguration entityTypeConfig = builder.AddEntityType(classInfo.ClassType); 74 | entitySetConfig = builder.AddEntitySet(classInfo.ClassType.Name, entityTypeConfig); 75 | if(classInfo.PersistentBaseClass != null) { 76 | EntitySetConfiguration baseClassEntitySetConfig = CreateEntitySet(classInfo.PersistentBaseClass, builder); 77 | entityTypeConfig.DerivesFrom(baseClassEntitySetConfig.EntityType); 78 | } else { 79 | if(classInfo.KeyProperty is ReflectionFieldInfo) { 80 | foreach(XPMemberInfo mi in classInfo.Members) { 81 | if(mi.IsAliased) { 82 | string aliasedExpr = ((PersistentAliasAttribute)mi.GetAttributeInfo(typeof(PersistentAliasAttribute))).AliasExpression; 83 | var aliasedCriteria = CriteriaOperator.Parse(aliasedExpr) as OperandProperty; 84 | if(!ReferenceEquals(null, aliasedCriteria) && aliasedCriteria.PropertyName == classInfo.KeyProperty.Name) { 85 | entityTypeConfig.HasKey(classInfo.ClassType.GetProperty(mi.Name)); 86 | break; 87 | } 88 | } 89 | } 90 | } else { 91 | entityTypeConfig.HasKey(classInfo.ClassType.GetProperty(classInfo.KeyProperty.Name)); 92 | } 93 | } 94 | return entitySetConfig; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /CS/ODataService/Controllers/ActionsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | using System.Web; 7 | using System.Web.Http; 8 | using DevExpress.Xpo; 9 | using WebApplication1.Models; 10 | using ODataService.Helpers; 11 | using Microsoft.AspNet.OData; 12 | using Microsoft.AspNet.OData.Routing; 13 | 14 | namespace WebApplication1.Controllers { 15 | public class ActionsController : ODataController { 16 | 17 | [ODataRoute("InitializeDatabase")] 18 | public IHttpActionResult InitializeDatabase() { 19 | DemoDataHelper.CleanupDatabase(); 20 | DemoDataHelper.CreateDemoData(); 21 | return Ok(); 22 | } 23 | 24 | [HttpGet] 25 | [ODataRoute("TotalSalesByYear(year={year})")] 26 | public IHttpActionResult TotalSalesByYear(int year) { 27 | using(UnitOfWork uow = new UnitOfWork()) { 28 | decimal result = uow.Query() 29 | .Where(o => o.Date.Value.Year == year) 30 | .Sum(o => o.OrderDetails.Sum(d => d.Quantity * d.UnitPrice)); 31 | return Ok(result); 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /CS/ODataService/Controllers/BaseDocumentController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | using System.Web; 7 | using System.Web.Http; 8 | using DevExpress.Xpo; 9 | using WebApplication1.Models; 10 | using ODataService.Helpers; 11 | using Microsoft.AspNet.OData; 12 | using Microsoft.AspNet.OData.Routing; 13 | 14 | namespace WebApplication1.Controllers { 15 | 16 | public class BaseDocumentController : ODataController { 17 | 18 | private UnitOfWork Session; 19 | 20 | [EnableQuery] 21 | public IQueryable Get() { 22 | Session = ConnectionHelper.CreateSession(); 23 | return Session.Query(); 24 | } 25 | 26 | [EnableQuery] 27 | public SingleResult Get([FromODataUri] int key) { 28 | Session = ConnectionHelper.CreateSession(); 29 | var result = Session.Query().Where(t => t.ID == key); 30 | return SingleResult.Create(result); 31 | } 32 | 33 | [HttpPost, HttpPut] 34 | public IHttpActionResult CreateRef([FromODataUri]int key, string navigationProperty, [FromBody] Uri link) { 35 | return StatusCode(ApiHelper.CreateRef(Request, key, navigationProperty, link)); 36 | } 37 | 38 | [HttpDelete] 39 | public IHttpActionResult DeleteRef([FromODataUri] int key, [FromODataUri] int relatedKey, string navigationProperty) { 40 | return StatusCode(ApiHelper.DeleteRef(key, relatedKey, navigationProperty)); 41 | } 42 | 43 | [HttpDelete] 44 | public IHttpActionResult Delete([FromODataUri] int key) { 45 | return StatusCode(ApiHelper.Delete(key)); 46 | } 47 | 48 | protected override void Dispose(bool disposing) { 49 | base.Dispose(disposing); 50 | if(disposing) { 51 | if(Session != null) { 52 | Session.Dispose(); 53 | Session = null; 54 | } 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /CS/ODataService/Controllers/ContractController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | using System.Web; 7 | using System.Web.Http; 8 | using DevExpress.Xpo; 9 | using WebApplication1.Models; 10 | using ODataService.Helpers; 11 | using Microsoft.AspNet.OData; 12 | using Microsoft.AspNet.OData.Routing; 13 | 14 | namespace WebApplication1.Controllers { 15 | public class ContractController : ODataController { 16 | 17 | private UnitOfWork Session; 18 | 19 | [EnableQuery] 20 | public IQueryable Get() { 21 | Session = ConnectionHelper.CreateSession(); 22 | return Session.Query(); 23 | } 24 | 25 | [EnableQuery] 26 | public SingleResult Get([FromODataUri] int key) { 27 | Session = ConnectionHelper.CreateSession(); 28 | var result = Session.Query().Where(t => t.ID == key); 29 | return SingleResult.Create(result); 30 | } 31 | 32 | [EnableQuery] 33 | public SingleResult GetCustomer([FromODataUri] int key) { 34 | Session = ConnectionHelper.CreateSession(); 35 | var result = Session.Query().Where(m => m.ID == key).Select(m => m.Customer); 36 | return SingleResult.Create(result); 37 | } 38 | 39 | [EnableQuery] 40 | public SingleResult GetParentDocument([FromODataUri] int key) { 41 | Session = ConnectionHelper.CreateSession(); 42 | var result = Session.Query().Where(m => m.ID == key).Select(m => m.ParentDocument); 43 | return SingleResult.Create(result); 44 | } 45 | 46 | [EnableQuery] 47 | public IQueryable GetLinkedDocuments([FromODataUri] int key) { 48 | Session = ConnectionHelper.CreateSession(); 49 | return Session.Query().Where(m => m.ID == key).SelectMany(t => t.LinkedDocuments); 50 | } 51 | 52 | 53 | [HttpPost] 54 | public IHttpActionResult Post(Contract contract) { 55 | if(!ModelState.IsValid) { 56 | return BadRequest(); 57 | } 58 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 59 | Contract entity = new Contract(uow) { 60 | ID = contract.ID, 61 | Date = contract.Date, 62 | Number = contract.Number 63 | }; 64 | uow.CommitChanges(); 65 | return Created(entity); 66 | } 67 | } 68 | 69 | [HttpPut] 70 | public IHttpActionResult Put([FromODataUri] int key, Contract contract) { 71 | if(!ModelState.IsValid) { 72 | return BadRequest(); 73 | } 74 | if(key != contract.ID) { 75 | return BadRequest(); 76 | } 77 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 78 | Contract existing = uow.GetObjectByKey(key); 79 | if(existing == null) { 80 | Contract entity = new Contract(uow) { 81 | ID = contract.ID, 82 | Date = contract.Date, 83 | Number = contract.Number 84 | }; 85 | uow.CommitChanges(); 86 | return Created(entity); 87 | } else { 88 | existing.Date = contract.Date; 89 | uow.CommitChanges(); 90 | return Updated(existing); 91 | } 92 | } 93 | } 94 | 95 | [HttpPatch] 96 | public IHttpActionResult Patch([FromODataUri] int key, Delta contract) { 97 | if(!ModelState.IsValid) { 98 | return BadRequest(); 99 | } 100 | var result = ApiHelper.Patch(key, contract); 101 | if(result != null) { 102 | return Updated(result); 103 | } 104 | return NotFound(); 105 | } 106 | 107 | [HttpDelete] 108 | public IHttpActionResult Delete([FromODataUri] int key) { 109 | return StatusCode(ApiHelper.Delete(key)); 110 | } 111 | 112 | [HttpPost, HttpPut] 113 | public IHttpActionResult CreateRef([FromODataUri]int key, string navigationProperty, [FromBody] Uri link) { 114 | return StatusCode(ApiHelper.CreateRef(Request, key, navigationProperty, link)); 115 | } 116 | 117 | [HttpDelete] 118 | public IHttpActionResult DeleteRef([FromODataUri] int key, [FromODataUri] int relatedKey, string navigationProperty) { 119 | return StatusCode(ApiHelper.DeleteRef(key, relatedKey, navigationProperty)); 120 | } 121 | 122 | protected override void Dispose(bool disposing) { 123 | base.Dispose(disposing); 124 | if(disposing) { 125 | if(Session != null) { 126 | Session.Dispose(); 127 | Session = null; 128 | } 129 | } 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /CS/ODataService/Controllers/CustomerController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Web.Http; 4 | using DevExpress.Xpo; 5 | using WebApplication1.Models; 6 | using ODataService.Helpers; 7 | using Microsoft.AspNet.OData; 8 | 9 | namespace WebApplication1.Controllers { 10 | public class CustomerController : ODataController { 11 | 12 | private UnitOfWork Session; 13 | 14 | [EnableQuery] 15 | public IQueryable Get() { 16 | Session = ConnectionHelper.CreateSession(); 17 | return Session.Query(); 18 | } 19 | 20 | [EnableQuery] 21 | public SingleResult Get([FromODataUri] string key) { 22 | Session = ConnectionHelper.CreateSession(); 23 | var result = Session.Query().Where(t => t.CustomerID == key); 24 | return SingleResult.Create(result); 25 | } 26 | 27 | [EnableQuery] 28 | public IQueryable GetOrders([FromODataUri] string key) { 29 | Session = ConnectionHelper.CreateSession(); 30 | return Session.Query().Where(m => m.CustomerID == key).SelectMany(m => m.Orders); 31 | } 32 | 33 | 34 | [HttpPost] 35 | public IHttpActionResult Post(Customer customer) { 36 | if(!ModelState.IsValid) { 37 | return BadRequest(); 38 | } 39 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 40 | Customer entity = new Customer(uow) { 41 | CustomerID = customer.CustomerID, 42 | CompanyName = customer.CompanyName 43 | }; 44 | uow.CommitChanges(); 45 | return Created(entity); 46 | } 47 | } 48 | 49 | [HttpPut] 50 | public IHttpActionResult Put([FromODataUri] string key, Customer customer) { 51 | if(!ModelState.IsValid) { 52 | return BadRequest(); 53 | } 54 | if(key != customer.CustomerID) { 55 | return BadRequest(); 56 | } 57 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 58 | Customer existing = uow.GetObjectByKey(key); 59 | if(existing == null) { 60 | Customer entity = new Customer(uow) { 61 | CustomerID = customer.CustomerID, 62 | CompanyName = customer.CompanyName 63 | }; 64 | uow.CommitChanges(); 65 | return Created(entity); 66 | } else { 67 | existing.CustomerID = customer.CustomerID; 68 | existing.CompanyName = customer.CompanyName; 69 | uow.CommitChanges(); 70 | return Updated(customer); 71 | } 72 | } 73 | } 74 | 75 | [HttpPatch] 76 | public IHttpActionResult Patch([FromODataUri] string key, Delta customer) { 77 | if(!ModelState.IsValid) { 78 | return BadRequest(); 79 | } 80 | var result = ApiHelper.Patch(key, customer); 81 | if(result != null) { 82 | return Updated(result); 83 | } 84 | return NotFound(); 85 | } 86 | 87 | [HttpDelete] 88 | public IHttpActionResult Delete([FromODataUri] string key) { 89 | return StatusCode(ApiHelper.Delete(key)); 90 | } 91 | 92 | [HttpPost, HttpPut] 93 | public IHttpActionResult CreateRef([FromODataUri]string key, string navigationProperty, [FromBody] Uri link) { 94 | return StatusCode(ApiHelper.CreateRef(Request, key, navigationProperty, link)); 95 | } 96 | 97 | [HttpDelete] 98 | public IHttpActionResult DeleteRef([FromODataUri] string key, [FromODataUri] int relatedKey, string navigationProperty) { 99 | return StatusCode(ApiHelper.DeleteRef(key, relatedKey, navigationProperty)); 100 | } 101 | 102 | protected override void Dispose(bool disposing) { 103 | base.Dispose(disposing); 104 | if(disposing) { 105 | if(Session != null) { 106 | Session.Dispose(); 107 | Session = null; 108 | } 109 | } 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /CS/ODataService/Controllers/OrderController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | using System.Web; 7 | using System.Web.Http; 8 | using DevExpress.Xpo; 9 | using WebApplication1.Models; 10 | using ODataService.Helpers; 11 | using Microsoft.AspNet.OData; 12 | using Microsoft.AspNet.OData.Routing; 13 | 14 | namespace WebApplication1.Controllers { 15 | public class OrderController : ODataController { 16 | 17 | private UnitOfWork Session; 18 | 19 | [EnableQuery] 20 | public IQueryable Get() { 21 | Session = ConnectionHelper.CreateSession(); 22 | return Session.Query(); 23 | } 24 | 25 | [EnableQuery] 26 | public SingleResult Get([FromODataUri] int key) { 27 | Session = ConnectionHelper.CreateSession(); 28 | var result = Session.Query().Where(t => t.ID == key); 29 | return SingleResult.Create(result); 30 | } 31 | 32 | [EnableQuery] 33 | public SingleResult GetCustomer([FromODataUri] int key) { 34 | Session = ConnectionHelper.CreateSession(); 35 | var result = Session.Query().Where(m => m.ID == key).Select(m => m.Customer); 36 | return SingleResult.Create(result); 37 | } 38 | 39 | [EnableQuery] 40 | public IQueryable GetOrderDetails([FromODataUri] int key) { 41 | Session = ConnectionHelper.CreateSession(); 42 | return Session.Query().Where(t => t.Order.ID == key); 43 | } 44 | 45 | [EnableQuery] 46 | public SingleResult GetParentDocument([FromODataUri] int key) { 47 | Session = ConnectionHelper.CreateSession(); 48 | var result = Session.Query().Where(m => m.ID == key).Select(m => m.ParentDocument); 49 | return SingleResult.Create(result); 50 | } 51 | 52 | [EnableQuery] 53 | public IQueryable GetLinkedDocuments([FromODataUri] int key) { 54 | Session = ConnectionHelper.CreateSession(); 55 | return Session.Query().Where(m => m.ID == key).SelectMany(t => t.LinkedDocuments); 56 | } 57 | 58 | [HttpPost] 59 | public IHttpActionResult Post(Order order) { 60 | if(!ModelState.IsValid) { 61 | return BadRequest(); 62 | } 63 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 64 | Order entity = new Order(uow) { 65 | ID = order.ID, 66 | Date = order.Date, 67 | OrderStatus = order.OrderStatus 68 | }; 69 | uow.CommitChanges(); 70 | return Created(entity); 71 | } 72 | } 73 | 74 | [HttpPut] 75 | public IHttpActionResult Put([FromODataUri] int key, Order order) { 76 | if(!ModelState.IsValid) { 77 | return BadRequest(); 78 | } 79 | if(key != order.ID) { 80 | return BadRequest(); 81 | } 82 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 83 | Order existing = uow.GetObjectByKey(key); 84 | if(existing == null) { 85 | Order entity = new Order(uow) { 86 | ID = order.ID, 87 | Date = order.Date, 88 | OrderStatus = order.OrderStatus 89 | }; 90 | uow.CommitChanges(); 91 | return Created(entity); 92 | } else { 93 | existing.Date = order.Date; 94 | uow.CommitChanges(); 95 | return Updated(existing); 96 | } 97 | } 98 | } 99 | 100 | [HttpPatch] 101 | public IHttpActionResult Patch([FromODataUri] int key, Delta order) { 102 | if(!ModelState.IsValid) { 103 | return BadRequest(); 104 | } 105 | var result = ApiHelper.Patch(key, order); 106 | if(result != null) { 107 | return Updated(result); 108 | } 109 | return NotFound(); 110 | } 111 | 112 | [HttpPost] 113 | [HttpPut] 114 | [ODataRoute("Order({key})/OrderDetails")] 115 | public IHttpActionResult AddToOrderDetails([FromODataUri] int key, OrderDetail orderDetail) { 116 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 117 | Order order = uow.GetObjectByKey(key); 118 | if(order == null) { 119 | return NotFound(); 120 | } 121 | OrderDetail existing = order.OrderDetails.FirstOrDefault(d => d.OrderDetailID == orderDetail.OrderDetailID); 122 | if(existing == null) { 123 | OrderDetail entity = new OrderDetail(uow) { 124 | Quantity = orderDetail.Quantity, 125 | UnitPrice = orderDetail.UnitPrice, 126 | }; 127 | order.OrderDetails.Add(entity); 128 | uow.CommitChanges(); 129 | return Created(entity); 130 | } else { 131 | existing.Quantity = orderDetail.Quantity; 132 | existing.UnitPrice = orderDetail.UnitPrice; 133 | uow.CommitChanges(); 134 | return Updated(existing); 135 | } 136 | } 137 | } 138 | 139 | [HttpDelete] 140 | public IHttpActionResult Delete([FromODataUri] int key) { 141 | return StatusCode(ApiHelper.Delete(key)); 142 | } 143 | 144 | [HttpPost, HttpPut] 145 | public IHttpActionResult CreateRef([FromODataUri]int key, string navigationProperty, [FromBody] Uri link) { 146 | return StatusCode(ApiHelper.CreateRef(Request, key, navigationProperty, link)); 147 | } 148 | 149 | [HttpDelete] 150 | public IHttpActionResult DeleteRef([FromODataUri] int key, string navigationProperty, [FromBody] Uri link) { 151 | return StatusCode(ApiHelper.DeleteRef(Request, key, navigationProperty, link)); 152 | } 153 | 154 | [HttpDelete] 155 | public IHttpActionResult DeleteRef([FromODataUri] int key, [FromODataUri] int relatedKey, string navigationProperty) { 156 | return StatusCode(ApiHelper.DeleteRef(key, relatedKey, navigationProperty)); 157 | } 158 | 159 | protected override void Dispose(bool disposing) { 160 | base.Dispose(disposing); 161 | if(disposing) { 162 | if(Session != null) { 163 | Session.Dispose(); 164 | Session = null; 165 | } 166 | } 167 | } 168 | } 169 | } -------------------------------------------------------------------------------- /CS/ODataService/Controllers/OrderDetailController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web.Http; 5 | using DevExpress.Xpo; 6 | using WebApplication1.Models; 7 | using ODataService.Helpers; 8 | using Microsoft.AspNet.OData; 9 | using Microsoft.AspNet.OData.Routing; 10 | 11 | namespace WebApplication1.Controllers { 12 | public class OrderDetailController : ODataController { 13 | 14 | private UnitOfWork Session; 15 | 16 | [EnableQuery] 17 | public IQueryable Get() { 18 | Session = ConnectionHelper.CreateSession(); 19 | return Session.Query(); 20 | } 21 | 22 | [EnableQuery] 23 | public SingleResult Get([FromODataUri] int key) { 24 | Session = ConnectionHelper.CreateSession(); 25 | var result = Session.Query().Where(t => t.OrderDetailID == key); 26 | return SingleResult.Create(result); 27 | } 28 | 29 | [HttpPut] 30 | public IHttpActionResult Put([FromODataUri] int key, OrderDetail orderDetail) { 31 | if(!ModelState.IsValid) { 32 | return BadRequest(); 33 | } 34 | if(key != orderDetail.OrderDetailID) { 35 | return BadRequest(); 36 | } 37 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 38 | OrderDetail existing = uow.GetObjectByKey(key); 39 | if(existing == null) { 40 | OrderDetail entity = new OrderDetail(uow) { 41 | Order = orderDetail.Order, 42 | Quantity = orderDetail.Quantity, 43 | UnitPrice = orderDetail.UnitPrice 44 | }; 45 | uow.CommitChanges(); 46 | return Created(entity); 47 | } else { 48 | existing.Quantity = orderDetail.Quantity; 49 | existing.UnitPrice = orderDetail.UnitPrice; 50 | uow.CommitChanges(); 51 | return Updated(existing); 52 | } 53 | } 54 | } 55 | 56 | [HttpPatch] 57 | public IHttpActionResult Patch([FromODataUri] int key, Delta orderDetail) { 58 | if(!ModelState.IsValid) { 59 | return BadRequest(); 60 | } 61 | var result = ApiHelper.Patch(key, orderDetail); 62 | if(result != null) { 63 | return Updated(result); 64 | } 65 | return NotFound(); 66 | } 67 | 68 | [HttpDelete] 69 | public IHttpActionResult Delete([FromODataUri] int key) { 70 | return StatusCode(ApiHelper.Delete(key)); 71 | } 72 | 73 | protected override void Dispose(bool disposing) { 74 | base.Dispose(disposing); 75 | if(disposing) { 76 | if(Session != null) { 77 | Session.Dispose(); 78 | Session = null; 79 | } 80 | } 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /CS/ODataService/Controllers/ProductController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Net; 4 | using System.Web.Http; 5 | using DevExpress.Xpo; 6 | using WebApplication1.Models; 7 | using ODataService.Helpers; 8 | using Microsoft.AspNet.OData; 9 | using Microsoft.AspNet.OData.Routing; 10 | 11 | namespace WebApplication1.Controllers { 12 | public class ProductController : ODataController { 13 | 14 | private UnitOfWork Session; 15 | 16 | [EnableQuery] 17 | public IQueryable Get() { 18 | Session = ConnectionHelper.CreateSession(); 19 | return Session.Query(); 20 | } 21 | 22 | [EnableQuery] 23 | public SingleResult Get([FromODataUri] int key) { 24 | Session = ConnectionHelper.CreateSession(); 25 | var result = Session.Query().Where(t => t.ProductID == key); 26 | return SingleResult.Create(result); 27 | } 28 | 29 | [HttpPost] 30 | public IHttpActionResult Post(Product product) { 31 | if(!ModelState.IsValid) { 32 | return BadRequest(); 33 | } 34 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 35 | Product entity = new Product(uow) { 36 | ProductName = product.ProductName, 37 | Picture = product.Picture 38 | }; 39 | uow.CommitChanges(); 40 | return Created(entity); 41 | } 42 | } 43 | 44 | [HttpPut] 45 | public IHttpActionResult Put([FromODataUri] int key, Product product) { 46 | if(!ModelState.IsValid) { 47 | return BadRequest(); 48 | } 49 | if(key != product.ProductID) { 50 | return BadRequest(); 51 | } 52 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 53 | Product existing = uow.GetObjectByKey(key); 54 | if(existing == null) { 55 | Product entity = new Product(uow) { 56 | ProductName = product.ProductName, 57 | Picture = product.Picture 58 | }; 59 | uow.CommitChanges(); 60 | return Created(entity); 61 | } else { 62 | existing.ProductName = product.ProductName; 63 | existing.Picture = product.Picture; 64 | uow.CommitChanges(); 65 | return Updated(product); 66 | } 67 | } 68 | } 69 | 70 | [HttpPatch] 71 | public IHttpActionResult Patch([FromODataUri] int key, Delta product) { 72 | if(!ModelState.IsValid) { 73 | return BadRequest(); 74 | } 75 | var result = ApiHelper.Patch(key, product); 76 | if(result != null) { 77 | return Updated(result); 78 | } 79 | return NotFound(); 80 | } 81 | 82 | [HttpDelete] 83 | public IHttpActionResult Delete([FromODataUri] int key) { 84 | return StatusCode(ApiHelper.Delete(key)); 85 | } 86 | 87 | [HttpPost, HttpPut] 88 | public IHttpActionResult CreateRef([FromODataUri]int key, string navigationProperty, [FromBody] Uri link) { 89 | return StatusCode(ApiHelper.CreateRef(Request, key, navigationProperty, link)); 90 | } 91 | 92 | [HttpDelete] 93 | public IHttpActionResult DeleteRef([FromODataUri] int key, [FromODataUri] int relatedKey, string navigationProperty) { 94 | return StatusCode(ApiHelper.DeleteRef(key, relatedKey, navigationProperty)); 95 | } 96 | 97 | protected override void Dispose(bool disposing) { 98 | base.Dispose(disposing); 99 | if(disposing) { 100 | if(Session != null) { 101 | Session.Dispose(); 102 | Session = null; 103 | } 104 | } 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /CS/ODataService/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="WebApplication1.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /CS/ODataService/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Web.Http; 4 | using System.Web.Http.Validation; 5 | using DevExpress.Xpo; 6 | using DevExpress.Xpo.DB; 7 | using ODataService.Helpers; 8 | 9 | namespace WebApplication1 10 | { 11 | public class WebApiApplication : System.Web.HttpApplication { 12 | protected void Application_Start() { 13 | GlobalConfiguration.Configuration.Services.Replace(typeof(IBodyModelValidator), new CustomBodyModelValidator()); 14 | GlobalConfiguration.Configure(WebApiConfig.Register); 15 | ConnectionHelper.EnsureDatabaseCreated(); 16 | XpoDefault.DataLayer = ConnectionHelper.CreateDataLayer(AutoCreateOption.SchemaAlreadyExists, true); 17 | } 18 | 19 | public class CustomBodyModelValidator : DefaultBodyModelValidator { 20 | readonly ConcurrentDictionary persistentTypes = new ConcurrentDictionary(); 21 | public override bool ShouldValidateType(Type type) { 22 | return persistentTypes.GetOrAdd(type, t => !typeof(IXPSimpleObject).IsAssignableFrom(t)); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CS/ODataService/Helpers/ApiHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Net.Http; 7 | using System.Web; 8 | using System.Web.Http; 9 | using DevExpress.Xpo; 10 | using Microsoft.AspNet.OData; 11 | 12 | namespace ODataService.Helpers { 13 | public static class ApiHelper { 14 | public static TEntity Patch(TKey key, Delta delta) where TEntity : class { 15 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 16 | TEntity existing = uow.GetObjectByKey(key); 17 | if(existing != null) { 18 | delta.CopyChangedValues(existing); 19 | uow.CommitChanges(); 20 | } 21 | return existing; 22 | } 23 | } 24 | 25 | public static HttpStatusCode Delete(TKey key) { 26 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 27 | TEntity existing = uow.GetObjectByKey(key); 28 | if(existing == null) { 29 | return HttpStatusCode.NotFound; 30 | } 31 | uow.Delete(existing); 32 | uow.CommitChanges(); 33 | return HttpStatusCode.NoContent; 34 | } 35 | } 36 | 37 | public static HttpStatusCode CreateRef(HttpRequestMessage request, TKey key, string navigationProperty, Uri link) { 38 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 39 | TEntity entity = uow.GetObjectByKey(key); 40 | if(entity == null) { 41 | return HttpStatusCode.NotFound; 42 | } 43 | var classInfo = uow.GetClassInfo(); 44 | var memberInfo = classInfo.FindMember(navigationProperty); 45 | if(memberInfo == null) { 46 | return HttpStatusCode.BadRequest; 47 | } 48 | object relatedKey = UriHelper.GetKeyFromUri(request, link); 49 | if(memberInfo.IsAssociationList) { 50 | var reference = uow.GetObjectByKey(memberInfo.CollectionElementType, relatedKey); 51 | var collection = (IList)memberInfo.GetValue(entity); 52 | collection.Add(reference); 53 | } else if(memberInfo.ReferenceType != null) { 54 | var reference = uow.GetObjectByKey(memberInfo.ReferenceType, relatedKey); 55 | memberInfo.SetValue(entity, reference); 56 | } else { 57 | return HttpStatusCode.BadRequest; 58 | } 59 | uow.CommitChanges(); 60 | return HttpStatusCode.NoContent; 61 | } 62 | } 63 | 64 | public static HttpStatusCode DeleteRef(HttpRequestMessage request, TKey key, string navigationProperty, Uri link) { 65 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 66 | TEntity entity = uow.GetObjectByKey(key); 67 | if(entity == null) { 68 | return HttpStatusCode.NotFound; 69 | } 70 | var classInfo = uow.GetClassInfo(); 71 | var memberInfo = classInfo.FindMember(navigationProperty); 72 | if(memberInfo == null) { 73 | return HttpStatusCode.BadRequest; 74 | } 75 | if(memberInfo.ReferenceType != null) { 76 | memberInfo.SetValue(entity, null); 77 | } else { 78 | return HttpStatusCode.BadRequest; 79 | } 80 | uow.CommitChanges(); 81 | return HttpStatusCode.NoContent; 82 | } 83 | } 84 | 85 | public static HttpStatusCode DeleteRef(TKey key, TRelatedKey relatedKey, string navigationProperty) { 86 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 87 | TEntity entity = uow.GetObjectByKey(key); 88 | if(entity == null) { 89 | return HttpStatusCode.NotFound; 90 | } 91 | var classInfo = uow.GetClassInfo(); 92 | var memberInfo = classInfo.FindMember(navigationProperty); 93 | if(memberInfo == null || !memberInfo.IsAssociationList) { 94 | return HttpStatusCode.BadRequest; 95 | } 96 | var reference = uow.GetObjectByKey(memberInfo.CollectionElementType, relatedKey); 97 | var collection = (IList)memberInfo.GetValue(entity); 98 | collection.Remove(reference); 99 | uow.CommitChanges(); 100 | return HttpStatusCode.NoContent; 101 | } 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /CS/ODataService/Helpers/ConnectionHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DevExpress.Xpo; 3 | using WebApplication1.Models; 4 | using DevExpress.Xpo.DB; 5 | using DevExpress.Xpo.Metadata; 6 | 7 | namespace ODataService.Helpers { 8 | 9 | public static class ConnectionHelper 10 | { 11 | static Type[] persistentTypes = new Type[] { 12 | typeof(BaseDocument), 13 | typeof(Customer), 14 | typeof(OrderDetail), 15 | typeof(Order), 16 | typeof(Contract), 17 | typeof(Product) 18 | }; 19 | public static Type[] GetPersistentTypes() 20 | { 21 | Type[] copy = new Type[persistentTypes.Length]; 22 | Array.Copy(persistentTypes, copy, persistentTypes.Length); 23 | return copy; 24 | } 25 | public static string ConnectionString { 26 | get { 27 | return System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; 28 | } 29 | } 30 | public static UnitOfWork CreateSession() { 31 | return new UnitOfWork() { IdentityMapBehavior = IdentityMapBehavior.Strong }; 32 | } 33 | public static IDataLayer CreateDataLayer(AutoCreateOption autoCreationOption, bool threadSafe) { 34 | var dictionary = new ReflectionDictionary(); 35 | dictionary.NullableBehavior = NullableBehavior.ByUnderlyingType; 36 | dictionary.GetDataStoreSchema(persistentTypes); 37 | if(threadSafe) { 38 | var provider = XpoDefault.GetConnectionProvider(XpoDefault.GetConnectionPoolString(ConnectionString), autoCreationOption); 39 | return new ThreadSafeDataLayer(dictionary, provider); 40 | } else { 41 | var provider = XpoDefault.GetConnectionProvider(ConnectionString, autoCreationOption); 42 | return new SimpleDataLayer(dictionary, provider); 43 | } 44 | } 45 | public static void EnsureDatabaseCreated() { 46 | using(IDataLayer dataLayer = CreateDataLayer(AutoCreateOption.DatabaseAndSchema, false)) { 47 | using(UnitOfWork uow = new UnitOfWork(dataLayer)) { 48 | uow.UpdateSchema(persistentTypes); 49 | } 50 | } 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /CS/ODataService/Helpers/DemoDataHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using DevExpress.Xpo; 6 | using DevExpress.Xpo.DB; 7 | using WebApplication1.Models; 8 | 9 | namespace ODataService.Helpers { 10 | public static class DemoDataHelper { 11 | 12 | public static void CleanupDatabase() { 13 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 14 | XPCollection docs = new XPCollection(uow); 15 | XPCollection customers = new XPCollection(uow); 16 | XPCollection products = new XPCollection(uow); 17 | XPCollection orderDetails = new XPCollection(uow); 18 | uow.Delete(orderDetails); 19 | uow.Delete(docs); 20 | uow.Delete(products); 21 | uow.Delete(customers); 22 | uow.CommitChanges(); 23 | } 24 | } 25 | 26 | public static void CreateDemoData() { 27 | using(UnitOfWork uow = ConnectionHelper.CreateSession()) { 28 | Product[] products = new Product[]{ 29 | new Product(uow) { 30 | ProductName = "Queso Cabrales", 31 | UnitPrice = 100.11m 32 | }, 33 | new Product(uow) { 34 | ProductName = "Gumbär Gummibärchen", 35 | UnitPrice = 200.12m 36 | }, 37 | new Product(uow) { 38 | ProductName = "Perth Pasties", 39 | UnitPrice = 300.13m 40 | }, 41 | new Product(uow) { 42 | ProductName = "Guaraná Fantástica", 43 | UnitPrice = 400.14m 44 | }, 45 | new Product(uow) { 46 | ProductName = "Vegie-spread", 47 | UnitPrice = 500.15m, 48 | Picture = new byte[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } 49 | } 50 | }; 51 | Customer[] customers = new Customer[] { 52 | new Customer(uow) { 53 | CustomerID="BSBEV", 54 | CompanyName="B's Beverages" 55 | }, 56 | new Customer(uow) { 57 | CustomerID="OCEAN", 58 | CompanyName="Océano Atlántico Ltda." 59 | }, 60 | new Customer(uow) { 61 | CustomerID="SANTG", 62 | CompanyName = "Santé Gourmet" 63 | }, 64 | new Customer(uow) { 65 | CustomerID="WARTH", 66 | CompanyName = "Wartian Herkku" 67 | } 68 | }; 69 | Order[] orders = new Order[] { 70 | new Order(uow) { 71 | Customer = customers[0], 72 | Date = new DateTime(2018, 01, 22, 10, 00, 01), 73 | OrderStatus = OrderStatus.New 74 | }, 75 | new Order(uow) { 76 | Customer = customers[1], 77 | Date = new DateTime(2018, 02, 22, 23, 14, 49), 78 | OrderStatus = OrderStatus.InProgress 79 | }, 80 | new Order(uow) { 81 | Customer = customers[2], 82 | Date = new DateTime(2018, 03, 15, 17, 00, 01), 83 | OrderStatus = OrderStatus.Completed 84 | }, 85 | new Order(uow) { 86 | Customer = customers[0], 87 | Date = new DateTime(2018, 06, 01, 00, 00, 00), 88 | OrderStatus = OrderStatus.Cancelled 89 | }, 90 | new Order(uow) { 91 | Date = new DateTime(2018, 06, 14, 10, 26, 00), 92 | OrderStatus = OrderStatus.New 93 | } 94 | }; 95 | for(int i = 0; i < orders.Length - 1; i++) { 96 | Order order = orders[i]; 97 | for(int j = 0; j < 3; j++) { 98 | var product = products[(i * 17 + j * 31) % products.Length]; 99 | order.OrderDetails.Add(new OrderDetail(uow) { 100 | Product = product, 101 | Quantity = 1, 102 | UnitPrice = product.UnitPrice.Value 103 | }); 104 | } 105 | } 106 | Contract[] contracts = new Contract[] { 107 | new Contract(uow) { 108 | Customer = customers[0], 109 | Date = new DateTime(2018, 01, 22, 10, 00, 01), 110 | Number = "2018-0001" 111 | }, 112 | new Contract(uow) { 113 | Customer = customers[1], 114 | Date = new DateTime(2018, 02, 22, 23, 14, 49), 115 | Number = "2018-0002" 116 | }, 117 | new Contract(uow) { 118 | Customer = customers[2], 119 | Date = new DateTime(2018, 03, 15, 17, 00, 01), 120 | Number = "2018-0003" 121 | } 122 | }; 123 | contracts[0].LinkedDocuments.Add(orders[0]); 124 | contracts[0].LinkedDocuments.Add(orders[1]); 125 | contracts[0].LinkedDocuments.Add(contracts[2]); 126 | contracts[1].LinkedDocuments.Add(orders[2]); 127 | uow.CommitChanges(); 128 | } 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /CS/ODataService/Helpers/UriHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNet.OData; 2 | using Microsoft.AspNet.OData.Extensions; 3 | using Microsoft.AspNet.OData.Routing; 4 | using Microsoft.OData.UriParser; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Net.Http; 9 | using System.Web.Http.Routing; 10 | 11 | namespace ODataService.Helpers { 12 | public static class UriHelper { 13 | public static TKey GetKeyFromUri(HttpRequestMessage request, Uri uri) { 14 | if(uri == null) { 15 | throw new ArgumentNullException("uri"); 16 | } 17 | var urlHelper = request.GetUrlHelper() ?? new UrlHelper(request); 18 | var pathHandler = (IODataPathHandler)request.GetRequestContainer().GetService(typeof(IODataPathHandler)); 19 | string serviceRoot = urlHelper.CreateODataLink( 20 | request.ODataProperties().RouteName, 21 | pathHandler, new List()); 22 | var odataPath = pathHandler.Parse(serviceRoot, uri.LocalPath, request.GetRequestContainer()); 23 | var keySegment = odataPath.Segments.OfType().FirstOrDefault(); 24 | if(keySegment == null) { 25 | throw new InvalidOperationException("The link does not contain a key."); 26 | } 27 | var value = keySegment.Keys.FirstOrDefault().Value; 28 | return (TKey)value; 29 | } 30 | 31 | public static string GetServiceRootUri(ODataController controller) { 32 | var routeName = controller.Request.ODataProperties().RouteName; 33 | ODataRoute odataRoute = controller.Configuration.Routes[routeName] as ODataRoute; 34 | var prefixName = odataRoute.RoutePrefix; 35 | if(!string.IsNullOrEmpty(prefixName)) { 36 | var requestUri = controller.Request.RequestUri.ToString(); 37 | var serviceRootUri = requestUri.Substring(0, requestUri.IndexOf(prefixName, StringComparison.InvariantCultureIgnoreCase) + prefixName.Length); 38 | return serviceRootUri; 39 | } else { 40 | return controller.Url.Content("~/"); 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /CS/ODataService/Models/BaseDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using DevExpress.Xpo; 6 | 7 | namespace WebApplication1.Models { 8 | 9 | [Persistent("BaseDocument")] 10 | public abstract class BaseDocument : XPLiteObject { 11 | public BaseDocument() { } 12 | public BaseDocument(Session session): base(session) { } 13 | 14 | int fID; 15 | [Key(true)] 16 | public int ID { 17 | get { return fID; } 18 | set { SetPropertyValue(nameof(ID), ref fID, value); } 19 | } 20 | 21 | DateTime? fDate; 22 | [Indexed(Name = @"DocumentDate")] 23 | public DateTime? Date { 24 | get { return fDate; } 25 | set { SetPropertyValue(nameof(Date), ref fDate, value); } 26 | } 27 | 28 | [Association(@"BaseDocumentLinkedDocuments")] 29 | public XPCollection LinkedDocuments { get { return GetCollection(nameof(LinkedDocuments)); } } 30 | 31 | BaseDocument fParentDocument; 32 | [Association(@"BaseDocumentLinkedDocuments")] 33 | [Persistent("ParentDocument")] 34 | public BaseDocument ParentDocument { 35 | get { return fParentDocument; } 36 | set { SetPropertyValue(nameof(BaseDocument), ref fParentDocument, value); } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /CS/ODataService/Models/Contracts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DevExpress.Xpo; 3 | using DevExpress.Data.Filtering; 4 | using System.Collections.Generic; 5 | 6 | namespace WebApplication1.Models { 7 | 8 | [Persistent("Contracts")] 9 | public class Contract : BaseDocument { 10 | 11 | public Contract(Session session) : base(session) { } 12 | public Contract() { } 13 | 14 | string fNumber; 15 | public string Number { 16 | get { return fNumber; } 17 | set { SetPropertyValue(nameof(Number), ref fNumber, value); } 18 | } 19 | 20 | Customer fCustomerID; 21 | [Size(5)] 22 | [Association(@"ContractsReferencesCustomers")] 23 | [Persistent("CustomerID")] 24 | public Customer Customer { 25 | get { return fCustomerID; } 26 | set { SetPropertyValue(nameof(Customer), ref fCustomerID, value); } 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /CS/ODataService/Models/Customers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DevExpress.Xpo; 3 | using DevExpress.Data.Filtering; 4 | using System.Collections.Generic; 5 | 6 | namespace WebApplication1.Models { 7 | 8 | [Persistent("Customers")] 9 | public class Customer : XPLiteObject { 10 | 11 | public Customer(Session session) : base(session) { } 12 | public Customer() : base(XpoDefault.Session) { } 13 | 14 | string fCustomerID; 15 | [Key] 16 | [Size(5)] 17 | [Nullable(false)] 18 | public string CustomerID { 19 | get { return fCustomerID; } 20 | set { SetPropertyValue(nameof(CustomerID), ref fCustomerID, value); } 21 | } 22 | 23 | string fCompanyName; 24 | [Indexed(Name = @"CompanyName")] 25 | [Size(40)] 26 | [Nullable(false)] 27 | public string CompanyName { 28 | get { return fCompanyName; } 29 | set { SetPropertyValue(nameof(CompanyName), ref fCompanyName, value); } 30 | } 31 | 32 | [Association(@"OrdersReferencesCustomers")] 33 | public XPCollection Orders { get { return GetCollection(nameof(Orders)); } } 34 | 35 | [Association(@"ContractsReferencesCustomers")] 36 | public XPCollection Contracts { get { return GetCollection(nameof(Contracts)); } } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /CS/ODataService/Models/OrderDetail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DevExpress.Xpo; 3 | using DevExpress.Data.Filtering; 4 | using System.Collections.Generic; 5 | 6 | namespace WebApplication1.Models { 7 | 8 | [Persistent("OrderDetails")] 9 | public class OrderDetail : XPLiteObject { 10 | public OrderDetail(Session session) : base(session) { } 11 | public OrderDetail() { } 12 | 13 | int fOrderDetailID; 14 | [Key(true)] 15 | public int OrderDetailID { 16 | get { return fOrderDetailID; } 17 | set { SetPropertyValue(nameof(OrderDetailID), ref fOrderDetailID, value); } 18 | } 19 | 20 | Order fOrder; 21 | [Association(@"OrdersReferencesOrderDetails")] 22 | [Persistent("OrderID")] 23 | public Order Order { 24 | get { return fOrder; } 25 | set { SetPropertyValue(nameof(Order), ref fOrder, value); } 26 | } 27 | 28 | Product fProduct; 29 | [Association(@"ProductsReferencesOrderDetails")] 30 | [Persistent("ProductID")] 31 | public Product Product { 32 | get { return fProduct; } 33 | set { SetPropertyValue(nameof(Product), ref fProduct, value); } 34 | } 35 | 36 | decimal fUnitPrice; 37 | [ColumnDbDefaultValue("(0)")] 38 | public decimal UnitPrice { 39 | get { return fUnitPrice; } 40 | set { SetPropertyValue(nameof(UnitPrice), ref fUnitPrice, value); } 41 | } 42 | 43 | short fQuantity; 44 | [ColumnDbDefaultValue("(1)")] 45 | public short Quantity { 46 | get { return fQuantity; } 47 | set { SetPropertyValue(nameof(Quantity), ref fQuantity, value); } 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /CS/ODataService/Models/OrderStatus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | 6 | namespace WebApplication1.Models { 7 | public enum OrderStatus { 8 | New, 9 | InProgress, 10 | Completed, 11 | Cancelled 12 | } 13 | } -------------------------------------------------------------------------------- /CS/ODataService/Models/Orders.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DevExpress.Xpo; 3 | using DevExpress.Data.Filtering; 4 | using System.Collections.Generic; 5 | 6 | namespace WebApplication1.Models { 7 | 8 | [Persistent("Orders")] 9 | public class Order : BaseDocument { 10 | 11 | public Order(Session session) : base(session) { } 12 | public Order() { } 13 | 14 | OrderStatus fOrderStatus; 15 | public OrderStatus OrderStatus { 16 | get { return fOrderStatus; } 17 | set { SetPropertyValue(nameof(OrderStatus), ref fOrderStatus, value); } 18 | } 19 | 20 | Customer fCustomerID; 21 | [Size(5)] 22 | [Association(@"OrdersReferencesCustomers")] 23 | [Persistent("CustomerID")] 24 | public Customer Customer { 25 | get { return fCustomerID; } 26 | set { SetPropertyValue(nameof(Customer), ref fCustomerID, value); } 27 | } 28 | 29 | [Association(@"OrdersReferencesOrderDetails")] 30 | [Aggregated] 31 | public XPCollection OrderDetails { get { return GetCollection(nameof(OrderDetails)); } } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /CS/ODataService/Models/Products.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using DevExpress.Xpo; 3 | using DevExpress.Data.Filtering; 4 | using System.Collections.Generic; 5 | 6 | namespace WebApplication1.Models { 7 | 8 | [Persistent("Products")] 9 | public partial class Product : XPLiteObject { 10 | 11 | public Product() { } 12 | public Product(Session session) : base(session) { } 13 | 14 | int fProductID; 15 | [Key(true)] 16 | public int ProductID { 17 | get { return fProductID; } 18 | set { SetPropertyValue(nameof(ProductID), ref fProductID, value); } 19 | } 20 | 21 | string fProductName; 22 | [Indexed(Name = @"ProductName")] 23 | [Size(40)] 24 | [Nullable(false)] 25 | public string ProductName { 26 | get { return fProductName; } 27 | set { SetPropertyValue(nameof(ProductName), ref fProductName, value); } 28 | } 29 | 30 | decimal? fUnitPrice; 31 | [ColumnDbDefaultValue("(0)")] 32 | public decimal? UnitPrice { 33 | get { return fUnitPrice; } 34 | set { SetPropertyValue(nameof(UnitPrice), ref fUnitPrice, value); } 35 | } 36 | 37 | byte[] fPicture; 38 | public byte[] Picture { 39 | get { return fPicture; } 40 | set { SetPropertyValue(nameof(Picture), ref fPicture, value); } 41 | } 42 | 43 | [Association(@"ProductsReferencesOrderDetails")] 44 | public XPCollection OrderDetails { get { return GetCollection(nameof(OrderDetails)); } } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /CS/ODataService/ODataService.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8 | 2.0 9 | {0B2F5AAD-834C-4E16-8FA5-22644CF82973} 10 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 11 | Library 12 | Properties 13 | ODataService 14 | ODataService 15 | v4.7.2 16 | true 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | true 27 | full 28 | false 29 | bin\ 30 | DEBUG;TRACE 31 | prompt 32 | 4 33 | 34 | 35 | true 36 | pdbonly 37 | true 38 | bin\ 39 | TRACE 40 | prompt 41 | 4 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Designer 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Global.asax 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | Web.config 97 | 98 | 99 | Web.config 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 24.2.7 108 | 109 | 110 | 5.2.6 111 | 112 | 113 | 7.4.1 114 | 115 | 116 | 5.2.6 117 | 118 | 119 | 2.1.1 120 | 121 | 122 | 11.0.2 123 | 124 | 125 | 4.3.0 126 | 127 | 128 | 4.3.0 129 | 130 | 131 | 4.3.0 132 | 133 | 134 | 4.3.0 135 | 136 | 137 | 4.3.0 138 | 139 | 140 | 4.3.0 141 | 142 | 143 | 4.3.0 144 | 145 | 146 | 4.3.0 147 | 148 | 149 | 4.3.0 150 | 151 | 152 | 4.3.0 153 | 154 | 155 | 4.3.0 156 | 157 | 158 | 4.3.0 159 | 160 | 161 | 162 | 10.0 163 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | True 173 | True 174 | 54417 175 | / 176 | http://localhost:54417/ 177 | False 178 | False 179 | 180 | False 181 | 182 | 183 | 184 | 185 | 192 | 193 | -------------------------------------------------------------------------------- /CS/ODataService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("WebApplication1")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("WebApplication1")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0b2f5aad-834c-4e16-8fa5-22644cf82973")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /CS/ODataService/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 14 | 15 | 26 | 27 | -------------------------------------------------------------------------------- /CS/ODataService/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 14 | 15 | 16 | 27 | 28 | -------------------------------------------------------------------------------- /CS/ODataService/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | -------------------------------------------------------------------------------- /CS/Tests/ActionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Default; 7 | using NUnit.Framework; 8 | 9 | namespace Tests { 10 | public class ActionTests : ODataTestsBase { 11 | 12 | [Test] 13 | public void FunctionTest() { 14 | Container container = GetODataContainer(); 15 | decimal sales2017 = container.TotalSalesByYear(2017).GetValue(); 16 | decimal sales2018 = container.TotalSalesByYear(2018).GetValue(); 17 | 18 | Assert.AreEqual(0, sales2017); 19 | Assert.AreEqual(3501.55m, sales2018); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /CS/Tests/CRUDTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using Default; 6 | using NUnit.Framework; 7 | using WebApplication1.Models; 8 | 9 | namespace Tests 10 | { 11 | [TestFixture] 12 | public class CRUDOperationTests : ODataTestsBase { 13 | 14 | [Test] 15 | public void CreateObject() { 16 | Container container = GetODataContainer(); 17 | Customer customer = new Customer() { 18 | CustomerID = "C0001", 19 | CompanyName = "Test Company" 20 | }; 21 | container.AddToCustomer(customer); 22 | var response = container.SaveChanges(); 23 | 24 | Assert.AreEqual(1, response.Count()); 25 | Assert.AreEqual((int)HttpStatusCode.Created, response.First().StatusCode); 26 | 27 | container = GetODataContainer(); 28 | Customer createdItem = container.Customer.Where(t => t.CustomerID == customer.CustomerID).First(); 29 | Assert.AreEqual(customer.CustomerID, createdItem.CustomerID); 30 | Assert.AreEqual(customer.CompanyName, createdItem.CompanyName); 31 | } 32 | 33 | [Test] 34 | public void UpdateObject() { 35 | Container container = GetODataContainer(); 36 | Customer customer = container.Customer.Where(t => t.CustomerID == "BSBEV").First(); 37 | 38 | customer.CompanyName = "Test Company Renamed"; 39 | container.UpdateObject(customer); 40 | var response = container.SaveChanges(); 41 | 42 | Assert.AreEqual(1, response.Count()); 43 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 44 | 45 | container = GetODataContainer(); 46 | Customer updatedItem = container.Customer.Where(t => t.CustomerID == "BSBEV").First(); 47 | Assert.AreEqual(customer.CustomerID, updatedItem.CustomerID); 48 | Assert.AreEqual(customer.CompanyName, updatedItem.CompanyName); 49 | } 50 | 51 | [Test] 52 | public void BatchUpdate() { 53 | Container container = GetODataContainer(); 54 | var customers = container.Customer.ToList(); 55 | foreach(var customer in customers) { 56 | customer.CompanyName += " -renamed"; 57 | container.UpdateObject(customer); 58 | } 59 | var response = container.SaveChanges(Microsoft.OData.Client.SaveChangesOptions.BatchWithSingleChangeset); 60 | 61 | Assert.AreEqual(4, response.Count()); 62 | foreach(var res in response) { 63 | Assert.AreEqual((int)HttpStatusCode.NoContent, res.StatusCode); 64 | } 65 | 66 | container = GetODataContainer(); 67 | customers = container.Customer.ToList(); 68 | foreach(var customer in customers) { 69 | Assert.IsTrue(customer.CompanyName.EndsWith(" -renamed")); 70 | } 71 | } 72 | 73 | [Test] 74 | public void DeleteObject() { 75 | Container container = GetODataContainer(); 76 | Customer customer = container.Customer.Where(t => t.CustomerID == "WARTH").First(); 77 | 78 | container.DeleteObject(customer); 79 | var response = container.SaveChanges(); 80 | 81 | Assert.AreEqual(1, response.Count()); 82 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 83 | } 84 | 85 | [Test] 86 | public void CreateObjectWithBlobField() { 87 | byte[] pictureData = new byte[256 * 256 * 4]; 88 | for(int i = 0; i < pictureData.Length; i++) { 89 | pictureData[i] = (byte)i; 90 | } 91 | Container container = GetODataContainer(); 92 | Product product = new Product() { 93 | ProductName = "test product", 94 | Picture = pictureData 95 | }; 96 | container.AddToProduct(product); 97 | var response = container.SaveChanges(); 98 | 99 | Assert.AreEqual(1, response.Count()); 100 | Assert.AreEqual((int)HttpStatusCode.Created, response.First().StatusCode); 101 | 102 | container = GetODataContainer(); 103 | Product createdItem = container.Product.Where(t => t.ProductName == product.ProductName).First(); 104 | 105 | Assert.IsNotNull(createdItem.Picture); 106 | Assert.AreEqual(product.Picture.Length, createdItem.Picture.Length); 107 | } 108 | 109 | [Test] 110 | public void UpdateObjectWithBlobField() { 111 | byte[] pictureData = new byte[256 * 256 * 4]; 112 | for(int i = 0; i < pictureData.Length; i++) { 113 | pictureData[i] = (byte)i; 114 | } 115 | Container container = GetODataContainer(); 116 | var product = container.Product.Where(t => t.ProductName == "Queso Cabrales").First(); 117 | byte[] oldPicture = product.Picture; 118 | product.Picture = pictureData; 119 | container.UpdateObject(product); 120 | var response = container.SaveChanges(); 121 | 122 | Assert.AreEqual(1, response.Count()); 123 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 124 | 125 | container = GetODataContainer(); 126 | Product updatedItem = container.Product.Where(t => t.ProductID == product.ProductID).First(); 127 | Assert.IsNull(oldPicture); 128 | Assert.IsNotNull(updatedItem.Picture); 129 | Assert.AreEqual(pictureData.Length, updatedItem.Picture.Length); 130 | } 131 | 132 | [Test] 133 | public void AddRelatedObject() { 134 | Container container = GetODataContainer(); 135 | Order order = container.Order.OrderByDescending(t => t.ID).First(); 136 | 137 | OrderDetail detail = new OrderDetail() { 138 | Quantity = 105, 139 | UnitPrice = 201.37m 140 | }; 141 | container.AddRelatedObject(order, "OrderDetails", detail); 142 | var response = container.SaveChanges(); 143 | 144 | Assert.AreEqual(1, response.Count()); 145 | Assert.AreEqual((int)HttpStatusCode.Created, response.First().StatusCode); 146 | 147 | container = GetODataContainer(); 148 | OrderDetail createdItem = container.OrderDetail.OrderByDescending(t => t.OrderDetailID).First(); 149 | Assert.AreEqual(detail.Quantity, createdItem.Quantity); 150 | Assert.AreEqual(detail.UnitPrice, createdItem.UnitPrice); 151 | Assert.Greater(createdItem.OrderDetailID, 0); 152 | } 153 | 154 | [Test] 155 | public void UpdateRelatedObject() { 156 | Container container = GetODataContainer(); 157 | Order order = container.Order.Expand(t => t.OrderDetails).OrderBy(t => t.Date).First(); 158 | OrderDetail detail = order.OrderDetails.OrderBy(t => t.OrderDetailID).First(); 159 | 160 | short oldQuantity = detail.Quantity; 161 | detail.Quantity += 1; 162 | container.UpdateObject(detail); 163 | var response = container.SaveChanges(); 164 | 165 | Assert.AreEqual(1, response.Count()); 166 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 167 | 168 | container = GetODataContainer(); 169 | OrderDetail updatedItem = container.Order.Expand(t => t.OrderDetails) 170 | .Where(t => t.ID == order.ID).First() 171 | .OrderDetails.Where(d => d.OrderDetailID == detail.OrderDetailID).First(); 172 | Assert.AreNotEqual(oldQuantity, updatedItem.Quantity); 173 | Assert.AreEqual(detail.Quantity, updatedItem.Quantity); 174 | } 175 | 176 | [Test] 177 | public void DeleteRelatedObject() { 178 | Container container = GetODataContainer(); 179 | Order order = container.Order.Expand(t => t.OrderDetails).OrderBy(t => t.Date).First(); 180 | OrderDetail detail = order.OrderDetails.OrderBy(t => t.OrderDetailID).First(); 181 | 182 | container.DeleteLink(order, "OrderDetails", detail); 183 | var response = container.SaveChanges(); 184 | 185 | Assert.AreEqual(1, response.Count()); 186 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 187 | 188 | container = GetODataContainer(); 189 | Order updatedItem = container.Order.Expand(t => t.OrderDetails).Where(t => t.ID == order.ID).First(); 190 | Assert.False(updatedItem.OrderDetails.Any(d => d.OrderDetailID == detail.OrderDetailID)); 191 | } 192 | 193 | [Test] 194 | public void DeleteAggregatedCollection() { 195 | Container container = GetODataContainer(); 196 | Order order = container.Order.Expand(t => t.OrderDetails).OrderBy(t => t.Date).First(); 197 | 198 | container.DeleteObject(order); 199 | var response = container.SaveChanges(); 200 | 201 | Assert.AreEqual(1, response.Count()); 202 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 203 | 204 | container = GetODataContainer(); 205 | var details = container.OrderDetail.Where(t => t.Order.ID == order.ID).ToList(); 206 | Assert.AreEqual(0, details.Count); 207 | } 208 | 209 | [Test] 210 | public void AddLink() { 211 | Container container = GetODataContainer(); 212 | Order order = container.Order.Where(t => t.Customer == null).OrderByDescending(t => t.ID).First(); 213 | Customer customer = container.Customer.Where(t => t.CustomerID == "BSBEV").First(); 214 | 215 | container.AddLink(customer, "Orders", order); 216 | var response = container.SaveChanges(); 217 | 218 | Assert.AreEqual(1, response.Count()); 219 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 220 | 221 | container = GetODataContainer(); 222 | Order updatedItem = container.Order.Expand(t => t.Customer).Where(t => t.ID == order.ID).First(); 223 | Assert.IsNull(order.Customer); 224 | Assert.NotNull(updatedItem.Customer); 225 | Assert.AreEqual(updatedItem.Customer.CustomerID, customer.CustomerID); 226 | } 227 | 228 | [Test] 229 | public void UpdateLink() { 230 | Container container = GetODataContainer(); 231 | Order order = container.Order.Where(t => t.Customer.CustomerID == "BSBEV").OrderByDescending(t => t.ID).First(); 232 | Customer customer = container.Customer.Where(t => t.CustomerID == "SANTG").First(); 233 | 234 | container.AddLink(customer, "Orders", order); 235 | var response = container.SaveChanges(); 236 | 237 | Assert.AreEqual(1, response.Count()); 238 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 239 | 240 | container = GetODataContainer(); 241 | Order updatedItem = container.Order.Expand(t => t.Customer).Where(t => t.ID == order.ID).First(); 242 | Assert.AreEqual(updatedItem.Customer.CustomerID, customer.CustomerID); 243 | } 244 | 245 | [Test] 246 | public void DeleteLink() { 247 | Container container = GetODataContainer(); 248 | Order order = container.Order.Expand(t => t.Customer).Where(t => t.Customer.CustomerID == "BSBEV").OrderByDescending(t => t.ID).First(); 249 | 250 | container.DeleteLink(order.Customer, "Orders", order); 251 | var response = container.SaveChanges(); 252 | 253 | Assert.AreEqual(1, response.Count()); 254 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 255 | 256 | container = GetODataContainer(); 257 | Order updatedItem = container.Order.Expand(t => t.Customer).Where(t => t.ID == order.ID).First(); 258 | Assert.IsNotNull(order.Customer); 259 | Assert.IsNull(updatedItem.Customer); 260 | } 261 | 262 | [Test] 263 | public void DeleteInheritedObject() { 264 | Container container = GetODataContainer(); 265 | int contractId = container.Contract.Where(t => t.Number == "2018-0003").First().ID; 266 | BaseDocument contract = container.BaseDocument.Where(t => t.ID == contractId).First(); 267 | 268 | container.DeleteObject(contract); 269 | var response = container.SaveChanges(); 270 | 271 | Assert.AreEqual(1, response.Count()); 272 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 273 | 274 | container = GetODataContainer(); 275 | int count = container.BaseDocument.ToList().Count(t => t.ID == contractId); 276 | Assert.AreEqual(0, count); 277 | } 278 | 279 | [Test] 280 | public void AddLinkToInherited() { 281 | Container container = GetODataContainer(); 282 | Order order = container.Order.Where(t => t.ParentDocument == null).OrderByDescending(t => t.ID).First(); 283 | Contract contract = container.Contract.Where(t => t.Number == "2018-0003").First(); 284 | 285 | container.AddLink(contract, "LinkedDocuments", order); 286 | var response = container.SaveChanges(); 287 | 288 | Assert.AreEqual(1, response.Count()); 289 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 290 | 291 | container = GetODataContainer(); 292 | Order updatedItem = container.Order.Expand(t => t.ParentDocument).Where(t => t.ID == order.ID).First(); 293 | Assert.IsNull(order.ParentDocument); 294 | Assert.NotNull(updatedItem.ParentDocument); 295 | Assert.AreEqual(updatedItem.ParentDocument.GetType(), typeof(Contract)); 296 | Assert.AreEqual(updatedItem.ParentDocument.ID, contract.ID); 297 | } 298 | 299 | [Test] 300 | public void UpdateLinkToInherited() { 301 | Container container = GetODataContainer(); 302 | Order order = container.Order.Where(t => (t.ParentDocument as Contract).Number == "2018-0002").First(); 303 | Contract contract = container.Contract.Where(t => t.Number == "2018-0003").First(); 304 | 305 | container.AddLink(contract, "LinkedDocuments", order); 306 | var response = container.SaveChanges(); 307 | 308 | Assert.AreEqual(1, response.Count()); 309 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 310 | 311 | container = GetODataContainer(); 312 | Order updatedItem = container.Order.Expand(t => t.ParentDocument).Where(t => t.ID == order.ID).First(); 313 | Assert.AreEqual(updatedItem.ParentDocument.ID, contract.ID); 314 | } 315 | 316 | [Test] 317 | public void DeleteLinkToInherited() { 318 | Container container = GetODataContainer(); 319 | Order order = container.Order.Expand(t => t.ParentDocument).Where(t => (t.ParentDocument as Contract).Number == "2018-0002").First(); 320 | 321 | container.DeleteLink(order.ParentDocument, "LinkedDocuments", order); 322 | var response = container.SaveChanges(); 323 | 324 | Assert.AreEqual(1, response.Count()); 325 | Assert.AreEqual((int)HttpStatusCode.NoContent, response.First().StatusCode); 326 | 327 | container = GetODataContainer(); 328 | Order updatedItem = container.Order.Expand(t => t.ParentDocument).Where(t => t.ID == order.ID).First(); 329 | Assert.IsNotNull(order.ParentDocument); 330 | Assert.IsNull(updatedItem.ParentDocument); 331 | } 332 | 333 | [Test] 334 | public void SetLink() { 335 | Container container = GetODataContainer(); 336 | Order order = new Order() { 337 | Date = DateTimeOffset.Now, 338 | OrderStatus = OrderStatus.New 339 | }; 340 | container.AddToOrder(order); 341 | var response1 = container.SaveChanges(); 342 | 343 | Assert.AreEqual(1, response1.Count()); 344 | Assert.AreEqual((int)HttpStatusCode.Created, response1.First().StatusCode); 345 | Customer customer = new Customer() { 346 | CustomerID = "Duffy", 347 | CompanyName = "Acme" 348 | }; 349 | container.AddToCustomer(customer); 350 | order.Customer = customer; 351 | container.SetLink(order, "Customer", customer); 352 | var response2 = container.SaveChanges(); 353 | Assert.AreEqual(2, response2.Count()); 354 | Assert.IsTrue(response2.Any(r => r.StatusCode == (int)HttpStatusCode.Created)); 355 | Assert.IsTrue(response2.Any(r => r.StatusCode == (int)HttpStatusCode.NoContent)); 356 | 357 | container = GetODataContainer(); 358 | Order createdItem = container.Order.Expand(t => t.Customer).Where(t => t.ID == order.ID).First(); 359 | Assert.IsNotNull(createdItem.Customer); 360 | Assert.AreEqual(order.Customer.CustomerID, createdItem.Customer.CustomerID); 361 | } 362 | 363 | 364 | [Test] 365 | public void RemoveLink() { 366 | Container container = GetODataContainer(); 367 | Order order = new Order() { 368 | Date = DateTimeOffset.Now, 369 | OrderStatus = OrderStatus.New 370 | }; 371 | container.AddToOrder(order); 372 | Customer customer = new Customer() { 373 | CustomerID = "Duffy", 374 | CompanyName = "Acme" 375 | }; 376 | container.AddToCustomer(customer); 377 | container.SetLink(order, "Customer", customer); 378 | var response1 = container.SaveChanges(); 379 | Assert.AreEqual(3, response1.Count()); 380 | Assert.AreEqual(2, response1.Count(r => r.StatusCode == (int)HttpStatusCode.Created)); 381 | Assert.IsTrue(response1.Any(r => r.StatusCode == (int)HttpStatusCode.NoContent)); 382 | 383 | container = GetODataContainer(); 384 | Order theOrder = container.Order.Expand(t => t.Customer).Where(t => t.ID == order.ID).First(); 385 | Assert.IsNotNull(theOrder.Customer); 386 | Assert.AreEqual(customer.CustomerID, theOrder.Customer.CustomerID); 387 | 388 | container.SetLink(theOrder, "Customer", null); 389 | var response2 = container.SaveChanges(); 390 | Assert.AreEqual(1, response2.Count()); 391 | Assert.AreEqual(1, response2.Count(r => r.StatusCode == (int)HttpStatusCode.NoContent)); 392 | 393 | container = GetODataContainer(); 394 | Order theOrder2 = container.Order.Expand(t => t.Customer).Where(t => t.ID == order.ID).First(); 395 | Assert.IsNull(theOrder2.Customer); 396 | } 397 | } 398 | } 399 | -------------------------------------------------------------------------------- /CS/Tests/Connected Services/ODataService/ConnectedService.json: -------------------------------------------------------------------------------- 1 | { 2 | "ProviderId": "Unchase.OData.ConnectedService", 3 | "Version": "1.3.11.0", 4 | "GettingStartedDocument": { 5 | "Uri": "http://odata.github.io/odata.net/" 6 | }, 7 | "ExtendedData": { 8 | "EnableNamingAlias": false, 9 | "IgnoreUnexpectedElementsAndAttributes": false, 10 | "GenerateDynamicPropertiesCollection": true, 11 | "DynamicPropertiesCollectionName": "DynamicProperties", 12 | "IncludeT4File": false, 13 | "OperationImportsGenerator": 0, 14 | "IncludeExtensionsT4File": false, 15 | "GenerateOperationImports": false, 16 | "ServiceName": "ODataService", 17 | "AcceptAllUntrustedCertificates": false, 18 | "Endpoint": "http://localhost:54417/$metadata", 19 | "EdmxVersion": { 20 | "Major": 4, 21 | "Minor": 0, 22 | "Build": 0, 23 | "Revision": 0, 24 | "MajorRevision": 0, 25 | "MinorRevision": 0 26 | }, 27 | "GeneratedFileNamePrefix": "Reference", 28 | "UseNameSpacePrefix": false, 29 | "NamespacePrefix": null, 30 | "UseDataServiceCollection": false, 31 | "UseAsyncDataServiceCollection": false, 32 | "OpenGeneratedFilesOnComplete": false, 33 | "LanguageOption": 0, 34 | "FunctionImports": null, 35 | "OperationImports": null, 36 | "ExcludedOperationImportsNames": "", 37 | "UseNetworkCredentials": false, 38 | "NetworkCredentialsUserName": null, 39 | "NetworkCredentialsPassword": null, 40 | "NetworkCredentialsDomain": null, 41 | "WebProxyUri": null, 42 | "UseWebProxy": false, 43 | "UseWebProxyCredentials": false, 44 | "WebProxyNetworkCredentialsUserName": null, 45 | "WebProxyNetworkCredentialsPassword": null, 46 | "WebProxyNetworkCredentialsDomain": null 47 | } 48 | } -------------------------------------------------------------------------------- /CS/Tests/GetDataTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Default; 7 | using NUnit.Framework; 8 | using WebApplication1.Models; 9 | 10 | namespace Tests { 11 | 12 | [TestFixture] 13 | public class SelectOperationsTests : ODataTestsBase { 14 | 15 | [Test] 16 | public void SelectSimple() { 17 | Container container = GetODataContainer(); 18 | var customers = container.Customer.ToList(); 19 | 20 | Assert.AreEqual(4, customers.Count); 21 | Assert.True(customers.Exists(c => c.CustomerID == "BSBEV" && c.CompanyName == "B's Beverages")); 22 | Assert.True(customers.Exists(c => c.CustomerID == "OCEAN" && c.CompanyName == "Océano Atlántico Ltda.")); 23 | Assert.True(customers.Exists(c => c.CustomerID == "SANTG" && c.CompanyName == "Santé Gourmet")); 24 | Assert.True(customers.Exists(c => c.CustomerID == "WARTH" && c.CompanyName == "Wartian Herkku")); 25 | } 26 | 27 | [Test] 28 | public void GetCount() { 29 | Container container = GetODataContainer(); 30 | int count = container.Customer.Count(); 31 | Assert.AreEqual(4, count); 32 | } 33 | 34 | [Test] 35 | public void FilterAndSort() { 36 | Container container = GetODataContainer(); 37 | var customers = container.Customer 38 | .Where(c => string.Compare(c.CustomerID, "C") >= 0) 39 | .OrderByDescending(c => c.CompanyName) 40 | .ToList(); 41 | 42 | Assert.AreEqual(3, customers.Count); 43 | Assert.IsTrue(customers[0].CustomerID == "WARTH"); 44 | Assert.IsTrue(customers[1].CustomerID == "SANTG"); 45 | Assert.IsTrue(customers[2].CustomerID == "OCEAN"); 46 | } 47 | 48 | [Test] 49 | public void SkipAndTake() { 50 | Container container = GetODataContainer(); 51 | var products = container.Product.OrderBy(t => t.UnitPrice) 52 | .Skip(1).Take(2) 53 | .ToList(); 54 | 55 | Assert.AreEqual(2, products.Count); 56 | Assert.AreEqual(200.12m, products[0].UnitPrice); 57 | Assert.AreEqual(300.13m, products[1].UnitPrice); 58 | } 59 | 60 | [Test] 61 | public void FilterByNull() { 62 | Container container = GetODataContainer(); 63 | var orders = container.Order 64 | .Where(o => o.Customer == null) 65 | .ToList(); 66 | Assert.AreEqual(1, orders.Count); 67 | } 68 | 69 | [Test] 70 | public void FilterByNotNull() { 71 | Container container = GetODataContainer(); 72 | var orders = container.Order 73 | .Where(o => o.Customer != null) 74 | .ToList(); 75 | Assert.AreEqual(4, orders.Count); 76 | } 77 | 78 | [Test] 79 | public void FilterByEnum() { 80 | Container container = GetODataContainer(); 81 | var orders = container.Order 82 | .Where(o => o.OrderStatus == OrderStatus.New) 83 | .ToList(); 84 | Assert.AreEqual(2, orders.Count); 85 | } 86 | 87 | [Test] 88 | public void Expand() { 89 | Container container = GetODataContainer(); 90 | var orders = container.Order 91 | .Expand(o => o.Customer) 92 | .Expand("OrderDetails($expand=Product)") 93 | .ToList(); 94 | 95 | orders = orders.OrderBy(o => o.Date).ToList(); 96 | Assert.AreEqual(5, orders.Count); 97 | Assert.AreEqual("BSBEV", orders[0].Customer.CustomerID); 98 | Assert.AreEqual("OCEAN", orders[1].Customer.CustomerID); 99 | Assert.AreEqual("SANTG", orders[2].Customer.CustomerID); 100 | Assert.AreEqual("BSBEV", orders[3].Customer.CustomerID); 101 | Assert.IsNull(orders[4].Customer); 102 | Assert.AreEqual(0, orders[4].OrderDetails.Count); 103 | for(int i = 0; i < 4; i++) { 104 | Assert.AreEqual(3, orders[i].OrderDetails.Count); 105 | for(int j = 0; j < 3; j++) { 106 | Assert.IsNotNull(orders[i].OrderDetails[j].Product); 107 | } 108 | } 109 | } 110 | 111 | [Test] 112 | public void FilterAndSortWithExpand() { 113 | Container container = GetODataContainer(); 114 | var orders = container.Order 115 | .Expand(o => o.Customer) 116 | .Expand("OrderDetails($expand=Product)") 117 | .Where(o => o.Customer.CustomerID != "OCEAN") 118 | .OrderBy(o => o.Customer.CompanyName) 119 | .ThenBy(o => o.Date) 120 | .ToList(); 121 | 122 | Assert.AreEqual(3, orders.Count); 123 | Assert.AreEqual("BSBEV", orders[0].Customer.CustomerID); 124 | Assert.AreEqual("BSBEV", orders[1].Customer.CustomerID); 125 | Assert.AreEqual("SANTG", orders[2].Customer.CustomerID); 126 | for(int i = 0; i < 3; i++) { 127 | Assert.AreEqual(3, orders[i].OrderDetails.Count); 128 | for(int j = 0; j < 3; j++) { 129 | Assert.IsNotNull(orders[i].OrderDetails[j].Product); 130 | } 131 | } 132 | } 133 | 134 | [Test] 135 | public void FilterByChildCollections() { 136 | Container container = GetODataContainer(); 137 | var orders = container.Order 138 | .Expand("OrderDetails($expand=Product)") 139 | .Where(o => o.OrderDetails.Any(t => t.Product.ProductName == "Queso Cabrales")) 140 | .ToList(); 141 | 142 | Assert.AreEqual(2, orders.Count); 143 | for(int i = 0; i < 2; i++) { 144 | Assert.IsTrue(orders[i].OrderDetails.Any(d => d.Product.ProductName == "Queso Cabrales")); 145 | } 146 | } 147 | 148 | [Test] 149 | public void FilterByDateTime() { 150 | DateTimeOffset startDate = new DateTimeOffset(new DateTime(2018, 03, 01)); 151 | DateTimeOffset endDate = new DateTimeOffset(new DateTime(2018, 06, 01)); 152 | Container container = GetODataContainer(); 153 | var orders = container.Order 154 | .Where(o => o.Date > startDate && o.Date <= endDate) 155 | .ToList(); 156 | 157 | Assert.AreEqual(2, orders.Count); 158 | for(int i = 0; i < orders.Count; i++) { 159 | Assert.Greater(orders[i].Date, startDate); 160 | Assert.LessOrEqual(orders[i].Date, endDate); 161 | } 162 | } 163 | 164 | [Test] 165 | public void FilterByDateTimePart() { 166 | Container container = GetODataContainer(); 167 | var orders = container.Order 168 | .Where(o => o.Date.Value.Year == 2018 && (o.Date.Value.Month == 3 || o.Date.Value.Month == 6)) 169 | .ToList(); 170 | Assert.AreEqual(3, orders.Count); 171 | } 172 | 173 | [Test] 174 | public void SelectBlobValues() { 175 | Container container = GetODataContainer(); 176 | var product = container.Product.Where(t => t.ProductName == "Vegie-spread").First(); 177 | 178 | Assert.IsNotNull(product.Picture); 179 | Assert.AreEqual(10, product.Picture.Length); 180 | for(int i = 0; i < 10; i++) { 181 | Assert.AreEqual(i + 1, product.Picture[i]); 182 | } 183 | } 184 | 185 | [Test] 186 | public void SelectWithProjection() { 187 | Container container = GetODataContainer(); 188 | var orders = container.Order.Expand(t => t.Customer).OrderBy(t => t.Date).ToList(); 189 | var projected = container.Order 190 | .OrderBy(t => t.Date) 191 | .Select(t => new { 192 | OrderID = t.ID, 193 | OrderDate = t.Date, 194 | Customer = (t.Customer != null) ? t.Customer.CompanyName : null 195 | }) 196 | .ToList(); 197 | 198 | Assert.AreEqual(orders.Count, projected.Count); 199 | for(int i = 0; i < orders.Count; i++) { 200 | Assert.AreEqual(orders[i].ID, projected[i].OrderID); 201 | Assert.AreEqual(orders[i].Date, projected[i].OrderDate); 202 | Assert.AreEqual(orders[i].Customer?.CompanyName, projected[i].Customer); 203 | } 204 | } 205 | 206 | [Test] 207 | public void SelectWithProjectionAndFunctions() { 208 | Container container = GetODataContainer(); 209 | var orders = container.Order.Expand(t => t.Customer).OrderBy(t => t.Date).ToList(); 210 | var projected = container.Order 211 | .OrderBy(t => t.Date) 212 | .Select(t => new { 213 | Year = t.Date.Value.Year, 214 | Customer = (t.Customer != null) ? t.Customer.CompanyName.ToUpper() : null 215 | }) 216 | .ToList(); 217 | 218 | Assert.AreEqual(orders.Count, projected.Count); 219 | for(int i = 0; i < orders.Count; i++) { 220 | Assert.AreEqual(orders[i].Date.Value.Year, projected[i].Year); 221 | Assert.AreEqual(orders[i].Customer?.CompanyName.ToUpper(), projected[i].Customer); 222 | } 223 | } 224 | 225 | [Test] 226 | public void ResourceReferenceProperty() { 227 | Container container = GetODataContainer(); 228 | int orderId = container.Order 229 | .Where(t => t.Date == new DateTimeOffset(new DateTime(2018, 06, 01))) 230 | .First().ID; 231 | 232 | var details = container.Order.ByKey(orderId).OrderDetails.Expand(t => t.Product).ToList(); 233 | Assert.AreEqual(3, details.Count); 234 | } 235 | 236 | [Test] 237 | public void InheritanceFilterByType() { 238 | Container container = GetODataContainer(); 239 | var documents = container.BaseDocument.ToList(); 240 | var orders = container.BaseDocument.Where(t => t is Order).ToList(); 241 | var contracts = container.BaseDocument.Where(t => t is Contract).ToList(); 242 | var notOrders = container.BaseDocument.Where(t => !(t is Order)).ToList(); 243 | Assert.AreEqual(5, orders.Count); 244 | Assert.AreEqual(3, contracts.Count); 245 | Assert.AreEqual(8, documents.Count); 246 | Assert.AreEqual(contracts.Count, notOrders.Count); 247 | } 248 | 249 | [Test] 250 | public void InheritanceCast() { 251 | Container container = GetODataContainer(); 252 | var contracts = container.BaseDocument.Where(t => (t as Contract).Number != "2018-0003").ToList(); 253 | Assert.AreEqual(2, contracts.Count); 254 | contracts = container.BaseDocument.Where(t => (t as Contract).Number == "2018-0003").ToList(); 255 | Assert.AreEqual(1, contracts.Count); 256 | } 257 | 258 | [Test] 259 | public void SelectInheritedReference() { 260 | Container container = GetODataContainer(); 261 | int orderId = container.Order 262 | .Where(t => t.Date == new DateTimeOffset(new DateTime(2018, 01, 22, 10, 00, 01))) 263 | .First().ID; 264 | BaseDocument parentDoc = container.Order.ByKey(orderId).ParentDocument.GetValue(); 265 | Assert.IsNotNull(parentDoc); 266 | Assert.AreEqual(typeof(Contract), parentDoc.GetType()); 267 | Assert.AreEqual("2018-0001", ((Contract)parentDoc).Number); 268 | } 269 | 270 | [Test] 271 | public void ExpandInheritedCollection() { 272 | Container container = GetODataContainer(); 273 | Contract contract = container.Contract.Expand(c => c.LinkedDocuments) 274 | .Where(t => t.Number == "2018-0001") 275 | .First(); 276 | Assert.AreEqual(3, contract.LinkedDocuments.Count); 277 | var linkedDocuments = contract.LinkedDocuments.OrderBy(t => t.GetType().Name).ToList(); 278 | Assert.AreEqual(typeof(Contract), linkedDocuments[0].GetType()); 279 | Assert.AreEqual(typeof(Order), linkedDocuments[1].GetType()); 280 | Assert.AreEqual(typeof(Order), linkedDocuments[2].GetType()); 281 | } 282 | 283 | [Test] 284 | public void CrossFilterByChildCollection() { 285 | Container container = GetODataContainer(); 286 | var contracts = container.Contract.Where(c => c.LinkedDocuments.Any(d => d.Date <= c.Date)).ToList(); 287 | Assert.AreEqual(1, contracts.Count); 288 | Assert.AreEqual("2018-0001", contracts[0].Number); 289 | } 290 | 291 | [Test] 292 | public void T727833() { 293 | Container container = GetODataContainer(); 294 | var orderDetail = container.OrderDetail.Expand("Product").Expand("Order($expand=Customer)").ToList().First(t => t.Order.Customer != null); 295 | int orderId = orderDetail.Order.ID; 296 | int productId = orderDetail.Product.ProductID; 297 | var orders = container.Order 298 | .Expand("Customer") 299 | .Expand("OrderDetails($expand=Product)") 300 | .Where(o => o.OrderDetails.Any(p => p.Product.ProductID == productId) && o.ID == orderId) 301 | .ToList(); 302 | Assert.AreEqual(1, orders.Count); 303 | Assert.AreEqual(orderId, orders[0].ID); 304 | Assert.IsNotNull(orders[0].Customer); 305 | } 306 | } 307 | } 308 | -------------------------------------------------------------------------------- /CS/Tests/ODataTestsBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using Default; 5 | using NUnit.Framework; 6 | 7 | namespace Tests { 8 | public abstract class ODataTestsBase { 9 | 10 | const string ODataServiceUrl = "http://localhost:5000/"; 11 | Process iisProcess = null; 12 | 13 | protected Container GetODataContainer() { 14 | return new Container(new Uri(ODataServiceUrl)); 15 | } 16 | 17 | [OneTimeSetUp] 18 | public void OneTimeSetup() { 19 | string iisExpressPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "IIS Express", "iisexpress.exe"); 20 | string appPath = Path.GetDirectoryName(this.GetType().Assembly.Location); 21 | appPath = Path.GetFullPath(Path.Combine(appPath, "..", "..", "..", "ODataService")); 22 | string args = string.Format("/path:\"{0}\" /port:5000", appPath); 23 | iisProcess = Process.Start(iisExpressPath, args); 24 | } 25 | 26 | [OneTimeTearDown] 27 | public void OneTimeTearDown() { 28 | if(iisProcess != null) { 29 | iisProcess.Kill(); 30 | } 31 | } 32 | 33 | [SetUp] 34 | public void Setup() { 35 | Container container = GetODataContainer(); 36 | container.InitializeDatabase().Execute(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /CS/Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2d5bf66b-fb41-49dd-8e4c-c97648cf159b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CS/Tests/Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {2D5BF66B-FB41-49DD-8E4C-C97648CF159B} 8 | Library 9 | Properties 10 | Tests 11 | Tests 12 | v4.7.2 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 15.7.2 60 | 61 | 62 | 7.5.1 63 | 64 | 65 | 3.10.1 66 | 67 | 68 | 3.10.0 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This code example is provided "as is" without warranty of any kind. Developer Express Inc ("DevExpress") disclaims all warranties, 2 | either express or implied, including the warranties of merchantability and fitness for a particular purpose. 3 | 4 | For licensing terms and conditions of DevExpress product(s) required for, or associated with the use of this code example, 5 | please refer to the applicable End-User License Agreement at https://www.devexpress.com/Support/licensingfaq.xml -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "autoGenerateVb": false, 3 | "runOnWeb": false 4 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | ![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/137757184/24.2.1%2B) 3 | [![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T830571) 4 | [![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183) 5 | [![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives) 6 | 7 | 8 | # How to Implement OData v4 Service with XPO (.NET Framework) 9 | 10 | > **Note**: 11 | > It is much easier to use the **[Web API Service](https://docs.devexpress.com/eXpressAppFramework/403394/backend-web-api-service)** with integrated authorization & CRUD operations based on ASP.NET Core OData 8.0 (OData v4) powered by EF Core and XPO ORM library instead. For more information, see [A 1-Click Solution for CRUD Web API Services with Role-based Access Control via EF Core & XPO (FREE)](https://community.devexpress.com/blogs/news/archive/2022/06/20/a-one-click-solution-for-role-based-access-control-asp-net-core-web-api-services-via-entity-framework-core-and-xpo-v22-1.aspx). 12 | 13 | This example describes how to implement an OData v4 service with XPO and .NET Framework 4.5. This example is an ASP.NET MVC 5 Web API project and provides a simple REST API for data access. For the .NET Core-based example, refer to [How to Implement OData v4 Service with XPO (.NET Core)](https://github.com/DevExpress-Examples/XPO_how-to-implement-odata4-service-with-xpo-netcore). 14 | 15 | ## Steps to Implement 16 | 17 | 1. Create a new **ASP.NET Web Application** project and select the **Web API** project template (refer to the **Create the Visual Studio Project** section in [this example](https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint) for details. 18 | 2. Install the following nuget packages: 19 | * DevExpress.Xpo 20 | * Microsoft.AspNet.OData 21 | 3. Define your data model - implement persistent classes and initialize the data layer. If you are new to XPO, refer to the following articles to learn how to do this: [Create Persistent Class](https://docs.devexpress.com/XPO/2077/create-a-data-model/create-a-persistent-object), [Map to Existing Tables](https://docs.devexpress.com/CoreLibraries/3264/devexpress-orm-tool/concepts/basics-of-creating-persistent-objects-for-existing-data-tables). 22 | 4. Add files from the **CS\OdataService\Helpers** folder in this example to your project ([Quick Tip: Add files to Visual Studio projects the easy way](https://blogs.msdn.microsoft.com/davidklinems/2007/12/18/quick-tip-add-files-to-visual-studio-projects-the-easy-way/)). 23 | 5. Modify the `Application_Start()` method declared in the *Global.asax* file: register the model body validator class and initialize the [Data Access Layer](https://docs.devexpress.com/CoreLibraries/2121/devexpress-orm-tool/feature-center/connecting-to-a-data-store/data-access-layer). 24 | 25 | ```cs 26 | protected void Application_Start() { 27 | GlobalConfiguration.Configuration.Services.Replace(typeof(IBodyModelValidator), new CustomBodyModelValidator()); 28 | GlobalConfiguration.Configure(WebApiConfig.Register); 29 | XpoDefault.DataLayer = ConnectionHelper.CreateDataLayer(AutoCreateOption.SchemaAlreadyExists, true); 30 | } 31 | 32 | public class CustomBodyModelValidator : DefaultBodyModelValidator { 33 | readonly ConcurrentDictionary persistentTypes = new ConcurrentDictionary(); 34 | public override bool ShouldValidateType(Type type) { 35 | return persistentTypes.GetOrAdd(type, t => !typeof(IXPSimpleObject).IsAssignableFrom(t)); 36 | } 37 | } 38 | ``` 39 | 40 | 6. Modify the *WebApiConfig.cs* file: create an ODataModelBuilder instance and register an EntitySet for each persistent class (refer to the [WebApiConfig.cs](CS/ODataService/App_Start/WebApiConfig.cs) file in this repository to learn how to automatically register all persistent classes): 41 | 42 | ```cs 43 | public static void Register(HttpConfiguration config) { 44 | config.Count().Filter().OrderBy().Expand().Select().MaxTop(null); 45 | ODataModelBuilder modelBuilder = CreateODataModelBuilder(); 46 | 47 | ODataBatchHandler batchHandler = 48 | new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer); 49 | 50 | config.MapODataServiceRoute( 51 | routeName: "ODataRoute", 52 | routePrefix: null, 53 | model: modelBuilder.GetEdmModel(), 54 | batchHandler: batchHandler); 55 | } 56 | 57 | static ODataModelBuilder CreateODataModelBuilder() { 58 | 59 | // Include persistent classes to the EdmModel: 60 | ODataModelBuilder builder = new ODataConventionModelBuilder(); 61 | var customers = builder.EntitySet("Customers"); 62 | customers.EntityType.HasKey(t => t.CustomerID); 63 | // .. 64 | 65 | // Include custom actions and functions into the EdmModel. 66 | builder.Function("TotalSalesByYear") 67 | .Returns() 68 | .Parameter("year"); 69 | 70 | return builder; 71 | } 72 | ``` 73 | 7. Add OData controllers to the Controllers folder. An OData controller is a class inherited from the Microsoft.AspNet.OData.ODataController class. Each controller represents a separate data model class created on the third step. 74 | 8. Implement the required methods in controllers (e.g., `Get`, `Post`, `Put`, `Patch`, `Delete`, etc.). For reference, use existing controllers in this example. For example: **CS\ODataService\Controllers\CustomersController.cs**. 75 | 76 | ## Does this example address your development requirements/objectives? 77 | 78 | [](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XPO_how-to-implement-odata4-service-with-xpo&~~~was_helpful=yes) [](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=XPO_how-to-implement-odata4-service-with-xpo&~~~was_helpful=no) 79 | 80 | (you will be redirected to DevExpress.com to submit your response) 81 | 82 | --------------------------------------------------------------------------------