Question

A c# client app is accessing a web api 2 odata controller by way of a service reference. How do yo do an insert? This code does not work:

 CourseServiceRef.Container container1;
 CourseServiceRef.NotNeeded notNeeded;

 notNeeded.Username1 = "test";
 notNeeded.Email = "test";           
 var serviceResponse = container1.SaveChanges();

The service reference is called CourseServiceRef. It contains an entity set called NotNeeded. Using Entity Framework 6.1

Was it helpful?

Solution

In case someone finds useful:

 Uri uri = new Uri("http://localhost:50222/odata");
         var container = new CourseServiceRef.Container(uri);
         CourseServiceRef.NotNeeded newTempAccount = new CourseServiceRef.NotNeeded()
            { 
               Email = model.UserName,
               Username1 = model.UserName 
            };

         if (newTempAccount != null)
        {
            container.AddToNotNeededs(newTempAccount);
            container.SaveChanges();
        }           
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top