Insert OData with Simple.OData.Client Inserts data but throws exeption

EquinoxDKEquinoxDK Member Posts: 6
Hey,

I have run into a weird problem. I am trying to make a simple CRUD (Create/Read/Update/Delete) example code in C# using Simple.OData.Client Client against OData V4. But when I try to insert a record I get the following exception: "Association {S} not found". The record is inserted but would really like to know why I get this exception.

Setup
Table with 4 fields:
id Integer
username Text 50
created Datetime
remark Text 50

Simple autogenerated Card page setup as webservice named test

URL in Appsetting is formatted: Http://Server:Port/Instance/OdataV4


C# Code
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();
        }

    }
}
Sign In or Register to comment.