Dataset bind to Gridview within WCF REST retrieval method and Linq to Sql
Posted
by
user643794
on Stack Overflow
See other posts from Stack Overflow
or by user643794
Published on 2011-03-03T22:20:12Z
Indexed on
2011/03/03
23:25 UTC
Read the original article
Hit count: 262
I used a WCF REST template to build a WCF service library to create PUT and GET calls. PUT method works fine sending my blob to a database.
On the GET, I want to be able to access the web service directly and display the results from a stored procedure as a dataset and bind this to a gridview. The stored procedure is a simple select statement, returning three of the four columns from the table. I have the following:
[WebGet(UriTemplate = "/?name={name}", ResponseFormat = WebMessageFormat.Xml)]
public List<Object> GetCollection(string name)
{
try
{
db.OpenDbConnection();
// Call to SQL stored procedure
return db.GetCustFromName(name);
}
catch (Exception e)
{
Log.Error("Stored Proc execution failed. ", e);
}
finally
{
db.CloseDbConnection();
}
return null;
}
I also added Linq to SQL class to include my database table and stored procedures access. I also created the Default.aspx file in addition to the other required files.
protected void Page_Load(object sender, EventArgs e)
{
ServiceDataContext objectContext = new ServiceDataContext();
var source = objectContext.GetCustFromName("Tiger");
Menu1.DataSource = source;
Menu1.DataBind();
}
But this gives me The entity type '' does not belong to any registered model.
Where should the data binding be done? What should be the return type for GetCollection()? I am stuck with this. Please provide help on how to do this.
© Stack Overflow or respective owner