Using EntityFramework, I have created an Entity Model including (SELECT) stored procedures. I have added Function Imports to get the SPs to map to complex types. This works for a query that returns multiple records.
However, for a query that only returns one record, I am currently getting this error:
Cannot convert type 'System.Data.Objects.ObjectResult<DAL.FullResponse>' to 'DAL.FullResponse'
I don’t know the multiplicity is the problem, but apart from the fact that the problem query takes a row identifier as a parameter, there is nothing about it that enforces a single row result (in fact when I ran the import function wizard it said I would be returning a collection of complex types.
I also don’t know if this is related but I have switched between versions of the EntityFramework while working on this project. After trying to use EF5 caused problems, I switched to EF4 with (until now) no problems.
Relevant code:
aspx
<asp:DetailsView ID="DetailsView1" DataKeyNames="ResponseID" runat="server"
AutoGenerateRows="True" Height="250px" Width="350px" BorderWidth="1px"
BorderStyle="Dashed" BorderColor="YellowGreen" CellPadding="0" CellSpacing="7"
GridLines="None" />
cs
protected void ShowData()
{
int respID = Convert.ToInt32(Request.QueryString.Get(0));
System.Diagnostics.Debug.Print("looking for ID: {0}", respID);
var responseDetailed = context.GetFullResponse(respID);
// get the data
DetailsView1.DataSource = (FullResponse)responseDetailed;
}
ShowData is called from Page_Load
Can someone point me to a way of fixing this? I’ve been stuck on it for nearly a day.
Try this: