Windows Azure Mobile Service – Invalid Operation Error.

Posted: November 22, 2013 in Live in a Cloudy World, Windows Azure

During the development of Windows Azure Mobile services I have faced some errors that I would love to share. It might help you with your development especially you might have nothing wrong in your code but with the logic.

Normally I have created the Windows Azure Mobile Services on Windows Azure with a data table let us call it mytable in this blog. I have created a class for the table in my visual studio project, I add into it the different type of properties I want to insert into the table. Like the following code:

public
class
mytable

{


public
string name { set; get; }


public
string desc { set; get; }

}

In my application code, which in my case was a Windows Phone application, I wrote the following code to insert the data into my table in the event handler of the button:

private
async
void tofa7a_Click(object sender, RoutedEventArgs e)

{


mytable at =
new
mytable();

at.name =
“abeer”;

at.desc =
“2ashta3’al l2anfokhak”;

 

 


await
App.MobileService.GetTable<mytable>().InsertAsync(at);

}

Certainly i have inserted the mobile service definition into my app.xaml.cs, to be able to consume it later on in my application. If you run the application you will get the following error:

The main reason I got this is because I didn’t define the ID property into the class that I created into my project. Let me clarify something more that you cannot change the value of the ID into your project because simply the Windows Azure mobile services increment automatically the value of the ID into your tables, so you only define the ID into your class to be able to read it, but not to insert an ID or you might face some errors.

So here is the solution of the code:

public
class
mytable

{


public
int id { set; get; }


public
string name { set; get; }


public
string desc { set; get; }

}

 

private
async
void tofa7a_Click(object sender, RoutedEventArgs e)

{


mytable at =
new
mytable();

at.name =
“abeer”;

at.desc =
“2ashta3’al l2anfokhak”;

 

 


await
App.MobileService.GetTable<mytable>().InsertAsync(at);

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s