using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using NAVCustomers.ServiceReference1; namespace NAVCustomers { class Program { static void Main(string[] args) { NAV nav = new NAV(new Uri("http://localhost:7048/DynamicsNAV/OData/Company('CRONUS%20International%20Ltd.')")); nav.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; Console.WriteLine("Printing list of current customers:"); PrintCustomersCalledCust(nav); Console.WriteLine("Adding new customer."); Customer newCustomer = new Customer(); newCustomer.No = "10001"; newCustomer.Name = "Customer Name"; nav.AddToCustomer(newCustomer); nav.SaveChanges(); Console.WriteLine("Printing list of current customers:"); PrintCustomersCalledCust(nav); newCustomer.Name += "Changed"; nav.UpdateObject(newCustomer); nav.SaveChanges(); Console.WriteLine("Printing list of current customers:"); PrintCustomersCalledCust(nav); } private static void PrintCustomersCalledCust(NAV nav) { var customers = from c in nav.Customer where c.Name.StartsWith("Cust") select c; Boolean customerFound = false; //foreach (Customer customer in customers) // { // customerFound = true; // Console.WriteLine("No.: {0} Name: {1}", customer.No, customer.Name); // } if (!customerFound) { Console.WriteLine("There are no customers that start with 'Cust'."); } } } }