Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert a new record in my DB using OData

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.

This is what it trows

like image 982
Guillermo Oramas R. Avatar asked Nov 13 '22 19:11

Guillermo Oramas R.


1 Answers

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).

like image 92
Vitek Karas MSFT Avatar answered Dec 22 '22 10:12

Vitek Karas MSFT