Skip to main content

ParameterLess construct

When I was creating my first cloud app that’s used Microsoft Azure for storage and computation purposes I came across a strange problem which wasn’t related to the Azure itself but was more related to the c# and the .net framework.
When I was writing the code I made a Class which had no parameter less construct. Objects of this class were then used in the program. Because this class was derived from Ienumerator I could actually user Foreach() on the objects of this class but to my surprise the code shown below was showing error at the highlighted line.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;
namespace WebRole1
{
public class mspDataServiceContext : TableServiceContext
{
public mspDataServiceContext(string baseAddress, StorageCredentials credentials)
: base(baseAddress, credentials)
{
}
static int c;
public IQueryable<msp> msps
{
get
{
return this.CreateQuery<msp>("msps");
}
}
static int Count()
{
return c;
}
public int AddMsp(msp m)
{
foreach (msp k in this.msps)
{
if (k.UserId == m.UserId)
return 0;
}
//for (int i = 0; i <mspDataServiceContext.Count(); i++)
//{
// if (m.UserId == msps.ElementAt(i).UserId)
// return 0;
//}
this.AddObject("msps", m);
this.SaveChanges();
c++;
return 1;//indicatiing successful addition
}
public int DeleteMsp(string UserId)
{
foreach (msp k in msps)
{
if (k.UserId == UserId)
{
this.DeleteObject(k);
this.SaveChanges();
c--;
return 1;//indicating sucessful deletion
}
}
return 0;//indicating missing entry
}
public int updateMspLocation(string UserId, double lat, double lon)
{
msp m = null;
foreach (msp k in msps)
{
if (k.UserId == UserId)
{
m = k;
this.DeleteObject(k);
this.SaveChanges();
break;
}
else return 0;
}
m.lat = lat;
m.lon = lon;
this.AddMsp(m);
this.SaveChanges();
return 1;//indicating successful updation
}
public void DeleteAll()
{
foreach (msp m in this.msps)
{
this.DeleteObject(m);
}
The error was later rectified by adding a parameter less construct in the class because the foreach() command was making a msp k in every step and there was no parameterless construct so the compiler wasn’t allowing it to be made.
link to the full project is given below

Comments

  1. gud yar parv....
    keep posting in the blog...
    and carry on the gud work..!!!

    ReplyDelete
  2. gr8 going yr
    this is request that pls post some articles to how to start learning azure

    ReplyDelete
  3. @samarth thankx
    and ya i will surely post things on how to start learning azure

    ReplyDelete

Post a Comment

Popular posts from this blog

Data manipulation in azure development storage by using web services – workaround

While developing the Azure project this was the biggest problem I came across and being just a newcomer in this area I could not solve it. So I figured a way around that worked perfectly well and then I used it to finally make a working project. Nearly all the solutions I came across in the different portals were about the same problem without the development storage anywhere in question but for the people who first need to make a working solution in the development storage using anything like the VS2010 there was no help nowhere. The problem was that while accessing data which was stored in a blob in cloud storage through a web service by a Silverlight client. It gives an impression to the storage of the cloud that this is being done by cross site scripting (this is what I got from all the different sources I read) and because this was not allowed the cloud project (webrole in my case) was blocking the request and was returning nothing in return. So this solution that I figured out i

Its a Dynamic(javascript) world

I thought we are living in a world which looked like this ||(or) mayb this http://www.ihatejavascript.com/ .. LOL being a web developer i was working with javascript and also at the same time i always preferred to work with something else... Silverlight, Flash mayb.. till recently.. i actually saw what JAVASCRIPT is || has become in the time i worked on ASP.Net MVC. Javascript evolved from a dynamic sort of functional language that was differently implemented by nearly every browser(and yes that was for you IE6 ) and every one hated him and i thought it still is that ulgy thing. till i just stumbled upon THIS This is an old video.. someone was just trying to bring the Javascript to server side. so now same developer /*Who a Javascript developer?*/ can work on both the sides.. client as well as web. and thought that things like these shouldn't be allowed on internet maybe because its a hour long video and now has around 233,492 views just consider the am