你如何插入odata edm?

时间:2014-04-25 14:54:57

标签: c# frameworks entity odata

c#客户端应用程序通过服务引用访问web api 2 odata控制器。你怎么做插入?此代码不起作用:

 CourseServiceRef.Container container1;
 CourseServiceRef.NotNeeded notNeeded;

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

服务引用称为CourseServiceRef。它包含一个名为NotNeeded的实体集。使用Entity Framework 6.1

1 个答案:

答案 0 :(得分:1)

如果有人觉得有用:

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