I've a OData services running on my application, and I've created a odata client, to update, save and deleted information using that OData services. The thing is I can access the data using the odata services but I don't know how to insert a new record or update a record. This is how i've been trying:
我在我的应用程序上运行了OData服务,并且我创建了一个odata客户端,使用该OData服务更新,保存和删除信息。问题是我可以使用odata服务访问数据,但我不知道如何插入新记录或更新记录。这就是我一直在尝试的方式:
When my Odata Client starts:
当我的Odata客户端启动时:
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
FutbolContext ctx = new FutbolContext(new Uri("http://localhost:56156/FutbolService.svc"));
DataServiceCollection<Team> TeamDS = new DataServiceCollection<Team>();
var qry = from w in ctx.Teams
select w;
TeamDS.Load(qry);
Team myTeam = new Equipo();
myTeam.Name = "Caracas F.C";
myTeam.City = "Caracas";
TeamDS.Add(myTeam);
ctx.SaveChanges();
}
I haven't been able to find tutorials about inserting and updating records through OData using C#. I hope some one can help me. Thanx in advance.
我无法找到有关使用C#通过OData插入和更新记录的教程。我希望有一个人可以帮助我。提前完成。
1 个解决方案
#1
1
Your code above loads the entities into a collection TeamDS but then it adds a new entity into a collection equipoDS. Since there's no equipoDS defined in your sample above I assume it's a completely different collection in which case it's not supposed to work. If you would add the entity into the TeamDS it will actually work (I tried a similar code myself).
上面的代码将实体加载到集合TeamDS中,然后将新实体添加到集合中。由于上面的示例中没有定义equipoDS,我认为它是一个完全不同的集合,在这种情况下它不应该工作。如果你将实体添加到TeamDS中它实际上会工作(我自己尝试过类似的代码)。
#1
1
Your code above loads the entities into a collection TeamDS but then it adds a new entity into a collection equipoDS. Since there's no equipoDS defined in your sample above I assume it's a completely different collection in which case it's not supposed to work. If you would add the entity into the TeamDS it will actually work (I tried a similar code myself).
上面的代码将实体加载到集合TeamDS中,然后将新实体添加到集合中。由于上面的示例中没有定义equipoDS,我认为它是一个完全不同的集合,在这种情况下它不应该工作。如果你将实体添加到TeamDS中它实际上会工作(我自己尝试过类似的代码)。