Edward Joell
asked on
Previously working MVC web project just stopped working after EF model Updated from database.
1.I have an entity framework based on a database.
2.I have several stored procedures in the database.
3.I imported these stored procedures into the Framework using "Add Function Import"
4.During the function import I created a complex Object call "SPName_Result"
5.I used this complex object to populate the Index view's table. This has been working successfully for three weeks now.
6.Today I made a change in the stored procedure.
7.I deleted the function from the function imports which also deleted the complex object.
8.I carried out a build.
9.I reimported the SP and recreated the complex object.
10.I then ran the app.
First off upon Running the App when the index view was called, an error occurred at a line in the Context file where the ObjectContext.ExecuteFunct ion attempted to run the stored procedure. It reported:
This time even before I could even compile, there was a error in the LINQ query being run in the Index Action Result of the controller
.
The above code started reporting that it could not carry out the Orderby ascending because the field was not present.
Once again back into the entity model and removed all references to that stored procedure, once again I updated the model from database and once again I imported that stored procedure and once again re-created the the complex object.
This time I was able to compile. However, this time it once again reported an error: on line 211 in the context file.
The program halted execution during the debug and delivered the following error:
This was baffling, for that column exists in the stored procedure, the imported function, and the complex object. So where can this alleged datareader possibly be getting its data if it does not match any of these objects? How is it the the column that allegedly doesn't match keeps changing?
Finally I was able to fix the original problem by deleting all of the complex Objects and the imported functions and re-rerun the import wizard using a different name for the object to resolve this.
However, after doing this and making sure the views and the action Result method in the controller referenced the newly named Complex object another error cropped up.
I was using a partial view on my index view to display a table of the returned complex objects. In the instructions on how to build a partial view on the plural soft website I was instructed that I had to make an IEnumerable of the model passed to the original parent view in order to be able to iterate through the returned model to create a table listing all of the objects. This has worked for a week. Now after making this change, suddenly I am getting the below error each time I try to open the Index view.
I tried to delete these files and recreate them from a copy of the project that was working 4 days ago, but to no avail I still keep getting the same error. So I removed the IEnumerable<> from the model and built it as is but I still got the same error. On the chance that this was due to a cached page, I closed everything did a full shut down and a cold boot in order to flush the cache (because the VS forums will not inform me of any other way to clear the cache.) Same Error. Which is odd as there should be no place where there is an IEnumerable.
I am at a loss here does anyone have any ideas?
Below is the Code for the relevant part of the controller and both of the view files:
Because I am at a work stoppage I will rename the project folder to Name_Broke and try reimporting the project I brought back from home after the blizzard. I still however have no guarentee that all of these errors will not occur again once I update from the database again.
I then rename the project folder to _Broke and reimported the project brought from home. I corrected the web.config, the database connections and the references. I then updated the model from the database. I checked the model browser and all of the new sotred procedures had been added imported as functions and as complex Objects. The changed stored procedure's Complex Objects reflected the changes made in the stored procedure in the database. But then when I ran it I once again got the error from the Dabase context file
It also delivered an error saying about the RequirementsController.cs file
But the Controller was save and the application was rebuilt all even before I f5'ed. So how can the source file be changed afterwards?
An entry on Stackoverflow said to delete both the dll and the pdb from the bin do a rebuilt to recreate them and that will fix it. But I have already done this several times with no change.
I have no idea what to do.
2.I have several stored procedures in the database.
3.I imported these stored procedures into the Framework using "Add Function Import"
4.During the function import I created a complex Object call "SPName_Result"
5.I used this complex object to populate the Index view's table. This has been working successfully for three weeks now.
6.Today I made a change in the stored procedure.
7.I deleted the function from the function imports which also deleted the complex object.
8.I carried out a build.
9.I reimported the SP and recreated the complex object.
10.I then ran the app.
First off upon Running the App when the index view was called, an error occurred at a line in the Context file where the ObjectContext.ExecuteFunct
The data reader is incompatible with the
specified 'VFS_ProcurementTrackModel.RequirementAll_Get_Result'. A member of the
type, 'CCID', does not have a corresponding column in the data reader with the same
name.
I found this baffling as I had removed said column from the stored procedure and regenerated that complex object after this was done. So I once again removed the imported function and the created complex object from the model. I once again imported the function and created a new complex object to expecting that now there should not be any issues. (I have learned over the past six weeks whenever there is anything wrong in EF it is more efficient to delete everything and start over than to spend days looking for the issue only to find that there is nothing wrong.)This time even before I could even compile, there was a error in the LINQ query being run in the Index Action Result of the controller
.
var model = from r in _db.Requirement_Get_All(12379)
orderby r.ReqNum ascending
select r;
The above code started reporting that it could not carry out the Orderby ascending because the field was not present.
Once again back into the entity model and removed all references to that stored procedure, once again I updated the model from database and once again I imported that stored procedure and once again re-created the the complex object.
This time I was able to compile. However, this time it once again reported an error: on line 211 in the context file.
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<RequirementAll_Get_Result>("Requirement_Get_All", userRecIDParameter);
The program halted execution during the debug and delivered the following error:
The data reader is incompatible with the
specified 'VFS_ProcurementTrackModel.RequirementAll_Get_Result'. A member of the
type, 'Import_CreateDate', does not have a corresponding column in the data reader
with the same name.
This was baffling, for that column exists in the stored procedure, the imported function, and the complex object. So where can this alleged datareader possibly be getting its data if it does not match any of these objects? How is it the the column that allegedly doesn't match keeps changing?
Finally I was able to fix the original problem by deleting all of the complex Objects and the imported functions and re-rerun the import wizard using a different name for the object to resolve this.
However, after doing this and making sure the views and the action Result method in the controller referenced the newly named Complex object another error cropped up.
I was using a partial view on my index view to display a table of the returned complex objects. In the instructions on how to build a partial view on the plural soft website I was instructed that I had to make an IEnumerable of the model passed to the original parent view in order to be able to iterate through the returned model to create a table listing all of the objects. This has worked for a week. Now after making this change, suddenly I am getting the below error each time I try to open the Index view.
The model item passed into the dictionary is of type
'System.Linq.OrderedEnumerable`2
[WorkingModel.Models.Requirement_Get_All_Result,System.String]',
but this dictionary requires a model item of
type 'WorkingModel.Models.Requirement_Get_All_Result'.
I tried to delete these files and recreate them from a copy of the project that was working 4 days ago, but to no avail I still keep getting the same error. So I removed the IEnumerable<> from the model and built it as is but I still got the same error. On the chance that this was due to a cached page, I closed everything did a full shut down and a cold boot in order to flush the cache (because the VS forums will not inform me of any other way to clear the cache.) Same Error. Which is odd as there should be no place where there is an IEnumerable.
I am at a loss here does anyone have any ideas?
Below is the Code for the relevant part of the controller and both of the view files:
Controller
public ActionResult Index()
{
//_db.Database.Connection.ConnectionString = "data source=CPVFSSQL200364\\SQL_2008R2_64;initial catalog=VFS_ProcurementTrack;user id=procdataapl;password=E22-CadPadVFS-prc";
var model = from r in _db.Requirement_Get_All(12379)
orderby r.ReqNum descending
select r;
return View(model);
}
"Index" View
@model WorkingModel.Models.Requirement_Get_All_Result
@{
ViewBag.Title = "Requirements for "; //+ Model.AMS;
}
<h2>Requirements</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@Html.Partial("_RequirementsGrid",Model)
"_RequirementsGrid" Partial View orignal one that worked:
@model IEnumerable< WorkingModel.Models.Requirement_Get_All_Result>
<table id="RequirementsView" class="scroll" border="1" title="Requirements" style="border-color:black">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.ReqNum)
</th>
<th>
@Html.DisplayNameFor(model => model.DoDIC)
</th>
<th>
@Html.DisplayNameFor(model => model.PPN)
</th>
<th>
@Html.DisplayNameFor(model => model.Quantity)
</th>
<th>
@Html.DisplayNameFor(model => model.CC_Description)
</th>
<th>
@Html.DisplayNameFor(model => model.CustDesc)
</th>
</tr>
</thead>
@foreach (var item in Model) {
<tr>
<td>
@Html.ActionLink(item.ReqNum.ToString(), "RequirementSummary", new { id=item.ReqID })
</td>
<td>
@Html.DisplayFor(modelItem => item.DoDIC)
</td>
<td>
@Html.DisplayFor(modelItem => item.PPN)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantity)
</td>
<td>
@Html.DisplayFor(modelItem => item.CC_Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.CustDesc)
</td>
</tr>
}
</table>
@Scripts.Render("~/Scripts/jquery.dataTables.js")
@Scripts.Render("~/Scripts/DoRequirementGrid.js")
Change made to "_RequirementsGrid" Partial View to try to get around this error:
@model WorkingModel.Models.Requirement_Get_All_Result
<table id="RequirementsView" class="scroll" border="1" title="Requirements" style="border-color:black">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.ReqNum)
</th>
<th>
@Html.DisplayNameFor(model => model.DoDIC)
</th>
<th>
@Html.DisplayNameFor(model => model.PPN)
</th>
<th>
@Html.DisplayNameFor(model => model.Quantity)
</th>
<th>
@Html.DisplayNameFor(model => model.CC_Description)
</th>
<th>
@Html.DisplayNameFor(model => model.CustDesc)
</th>
</tr>
</thead>
@foreach (var item in Model) {
<tr>
<td>
@Html.ActionLink(item.ReqNum.ToString(), "RequirementSummary", new { id=item.ReqID })
</td>
<td>
@Html.DisplayFor(modelItem => item.DoDIC)
</td>
<td>
@Html.DisplayFor(modelItem => item.PPN)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantity)
</td>
<td>
@Html.DisplayFor(modelItem => item.CC_Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.CustDesc)
</td>
</tr>
}
</table>
@Scripts.Render("~/Scripts/jquery.dataTables.js")
@Scripts.Render("~/Scripts/DoRequirementGrid.js")
Because I am at a work stoppage I will rename the project folder to Name_Broke and try reimporting the project I brought back from home after the blizzard. I still however have no guarentee that all of these errors will not occur again once I update from the database again.
I then rename the project folder to _Broke and reimported the project brought from home. I corrected the web.config, the database connections and the references. I then updated the model from the database. I checked the model browser and all of the new sotred procedures had been added imported as functions and as complex Objects. The changed stored procedure's Complex Objects reflected the changes made in the stored procedure in the database. But then when I ran it I once again got the error from the Dabase context file
"The data reader is incompatible with the
specified 'VFS_ProcurementTrackModel.Requirement_Get_All_Result'. A member of the
type, 'CustomerCode', does not have a corresponding column in the data reader with
the same name."
It also delivered an error saying about the RequirementsController.cs file
The source file is differen from when the module was built. Would you like the debugger to use it any way?
But the Controller was save and the application was rebuilt all even before I f5'ed. So how can the source file be changed afterwards?
An entry on Stackoverflow said to delete both the dll and the pdb from the bin do a rebuilt to recreate them and that will fix it. But I have already done this several times with no change.
I have no idea what to do.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This was merely a work-around because I was not able to get my project to go back to doing what it was before. But I can at least get on with my work.
If someone wants to take a stab at all of the other issues, be my guest and I will happily award you the points, (if it works.) I will preserve the broken project as a monument to hubris and to provide a test bed for any proposed solutions.
If someone wants to take a stab at all of the other issues, be my guest and I will happily award you the points, (if it works.) I will preserve the broken project as a monument to hubris and to provide a test bed for any proposed solutions.
ASKER
Open in new window
But nowhere in the project references, the packages, the bin, web.config, and package.config file is this assembly being reference. The Account Views folder is gone as well as the AccountController. A the assembly and the pdb have been deleted and recreated. The cache was wiped by doing a full shutdown and cold boot. Yet that error persist which is preventing me from doing any trouble shooting on the problem above.
I added all the references back to th project. Same error. I compared the project with one created fresj frpom the template. The only two references the broken project had that the new one didn't were System.Runtime.Serializati
There was no project ref to Microsoft.Web.WebPages.OAu