Java SSH vs ASP.NET MVC

2020/6/7

Java平台企业系统开发普遍使用SSH(Struts+Spring+Hibernate),随着SSH各框架版本的升级,特别是Spring的不断改进,貌似可以不用Struts了。

.NET平台企业系统开发也有了类似的东西,ASP.NET MVC +Entity Framework。微软总是把已有的技术做得更容易使用,ASP.NET MVC +Entity Framework是不是又一个实证呢?

使用Visual Studio 2013,你基本不需写代码(只需写模型类,代码非常简单),就可以实现数据库的增删改查。

Visual Studio 2013内置了Entity Framework 5,如果升级为Entity Framework 6,创建控制器时会提示MVC基架不支持Entity Framework 6或更高版本。

ASP.NET MVC升级到5.2.7,添加控制器时会弹出添加支架窗口,这个窗口有MVC 5控制器。能够添加MVC 5控制器。

删除原来的控制器,重新添加控制器,运行程序报错

警告    1    发现同一依赖程序集的不同版本间存在冲突。在 Visual Studio 中,请双击此警告(或选择此警告并按 Enter)以修复冲突;否则,请将以下绑定重定向添加到应用程序配置文件中的“runtime”节点: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Web.Razor" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Web.WebPages.Razor" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /></dependentAssembly></assemblyBinding>  

错误    1    无法将类型“System.Data.EntityState”隐式转换为“System.Data.Entity.EntityState”。存在一个显式转换(是否缺少强制转换?)    E:\Users\lenovo\Documents\Visual Studio 2013\Projects\MvcApplication2\myweb\Controllers\APOrderDetailController.cs   

错误    5    “EntityState”是“System.Data.EntityState”和“System.Data.Entity.EntityState”之间的不明确的引用    E:\Users\lenovo\Documents\Visual Studio 2013\Projects\MvcApplication2\myweb\Controllers\APOrderDetailController.cs 

或许应该先安装MVC再安装EF,在包管理器控制台输入命令

先卸载EF:Uninstall-Package EntityFramework -Force 
在安装EF6.4.4:Install-Package EntityFramework –Version 6.4.4

能运行了,但是访问页面报错

安全透明方法“WebMatrix.WebData.PreApplicationStartCode.Start()”尝试访问安全关键方法“System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)”失败。

删除web.config中的下面的代码

            <dependentAssembly>
                <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Razor" publicKeyToken="31BF3856AD364E35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
            </dependentAssembly>

报错信息如下

{"The model backing the 'APOrderContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)."}

包管理器控制台中运行Add-Migration
结果如下:

Add-Migration
位于命令管道位置 1 的 cmdlet Add-Migration
请为以下参数提供值:
Name: myweb
使用“1”个参数调用“LoadFrom”时发生异常:“未能加载文件或程序集“file:///E:\Users\lenovo\Documents\Visual Studio 2013\Projects\MvcApplication2\packages\EntityFramework.6.4.4\tools\EntityFramework.PowerShell.Utility.dll”或它的某一个依赖项。系统找不到指定的文件。”
所在位置 E:\Users\lenovo\Documents\Visual Studio 2013\Projects\MvcApplication2\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:398 字符: 62
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $toolsPath EntityFramework.PowerShell.Utility.dll))
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
 
不能对值为空的表达式调用方法。
所在位置 E:\Users\lenovo\Documents\Visual Studio 2013\Projects\MvcApplication2\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:399 字符: 50
+     $dispatcher = $utilityAssembly.CreateInstance <<<< (
    + CategoryInfo          : InvalidOperation: (CreateInstance:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
使用“8”个参数调用“CreateInstanceFrom”时发生异常:“未能加载文件或程序集“file:///E:\Users\lenovo\Documents\Visual Studio 2013\Projects\MvcApplication2\packages\EntityFramework.6.4.4\tools\EntityFramework.PowerShell.dll”或它的某一个依赖项。系统找不到指定的文件
。”
所在位置 E:\Users\lenovo\Documents\Visual Studio 2013\Projects\MvcApplication2\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 字符: 31
+     $domain.CreateInstanceFrom <<<< (
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
 

结果解决方案中的文件都不见了。

关闭解决方案,重新打开,可以看到原来的文件了。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值