Archive for November, 2013

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