Search code examples
azureasp.net-mvc-3-areasazure-table-storage

Azure TableStorage HowTo?


I want to store Contacts on to Azure table(name and gender as a property). so I basically two classes . the one which derives from the TableSerivceContext and the other from TableServiceEntity. now I cant connect the pieces. What I will really do at the cotroller(I use MVC3)

tnx for any hint?


Solution

  • im assuming that you are receiving the properties (name and gender) via post from a view.
    so your controller might be like this

    public ActionResult DoSomething(User model)
    {
    
    }
    

    so what you need to do is.. that. make a new ofject of the class thats derived from the TableServiceEntity. and assign the Properties. like this

    var tableUser = new TableUser(){Name = model.Name, Gender=model.Gender}
    

    then from the class derived from TableServiceContext make an object. and use AddObject() method to add the user to the table
    http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.addobject.aspx