This MVC Futures code will not execute. Why is it failing to recognize the System.Data.EntityState?
I copied the MVC Futures Base templates into my project. This code will not run.
@using System.Data开发者_如何转开发;
@functions{
bool ShouldShow(ModelMetadata metadata) {
return metadata.ShowForEdit
&& metadata.ModelType != typeof(System.Data.EntityState) <--This gives an error that entityState does not exist in namespace System.Data
&& !metadata.IsComplexType
&& !ViewData.TemplateInfo.Visited(metadata);
}
}
In the <assemblies>
section of your main ~/web.config
(not the one in ~/views/web.config
) file add the following line:
<assemblies>
...
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
This will ensure that the dynamically generated assemblies from the views will reference this assembly so that you can use types from it.
As a reference, if you are not using the EntityFramework in your project (like myself), it's safe to delete that line and avoid the error without including EF.
精彩评论