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:
When my Odata Client starts:
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With