Insert OData with Simple.OData.Client Inserts data but throws exeption
EquinoxDK
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
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();
}
}
}
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions