using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using Simple.OData.Client; namespace ODataSpike2 { class Program { static void Main(string[] args) { /// Demo CRUD functionality NAV from C# using Simple.OData.Client /// /// https://github.com/simple-odata-client/Simple.OData.Client/wiki/Getting-started-with-Simple.OData.Client var Client = new ODataClient(new ODataClientSettings( new Uri(ConfigurationManager.AppSettings["ODataURL"].ToString()), CredentialCache.DefaultNetworkCredentials )); Task.Run(async () => { try { #region Create Console.WriteLine("Create"); var demodata = await Client.For("test").Set(new { id = 666, created = DateTime.Now, remark = "From C#", username = "system" }).QueryOptions("company=CRONUS Danmark A/S").InsertEntryAsync(); #endregion #region Read Console.WriteLine("Read"); var test = await Client.For<Test>().QueryOptions("company=CRONUS Danmark A/S").FindEntriesAsync(); foreach (var item in test) { Console.WriteLine(item.id); Console.WriteLine(item.username); Console.WriteLine(item.created); Console.WriteLine(item.remark); } Console.WriteLine(test.Count()); #endregion #region Update Console.WriteLine("Update"); #endregion #region Delete Console.WriteLine("Delete"); await Client.For("test").Key(666).QueryOptions("company=CRONUS Danmark A/S").DeleteEntryAsync(); #endregion } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Press any key"); }); Console.ReadLine(); } } }