繁体   English   中英

【ASP.NET MVC5 VB】不能使用脚手架,报错

[英]【ASP.NET MVC5 VB】 Cannot use Scaffolding with error

我正在使用翻译工具。
我正在使用 Microsoft 官方文档,但在此过程中发生了错误。

文档说它在 C# 中,所以我正在用 VB 编写它的代码。

https://docs.microsoft.com/ja-jp/ef/core/modeling/entity-properties?tabs=data-annotations%2Cwithout-nrt

https://docs.microsoft.com/ja-jp/aspnet/mvc/overview/getting-started/introduction/creating-a-connection-string


我已经设置了数据 model 并将其连接到数据库,然后在弹出脚手架屏幕并按添加后,出现错误。
我无法创建 controller。

请让我知道该怎么做。

添加 controller 01
添加 controller 02
错误信息


【错误信息(翻译)】
错误
运行所选代码生成器时出错。
无法获取“quot_System.MvcSupplier.Models.Supplier”的元数据。
该序列不包含任何匹配元素。

型号/供应商.vb

Imports System.ComponentModel.DataAnnotations
Imports System.ComponentModel.DataAnnotations.Schema
Imports System.Data.Entity

Namespace MvcSupplier.Models
    Public Class Supplier
        Public Property Id As Integer
        <Column("仕入先コード", TypeName:="varchar(10)")>
        Public Property SupplierCode As String
    End Class
    Public Class MvcSupplierContext
        Inherits DbContext
        Public Property Suppliers As DbSet(Of Supplier)
    End Class
End Namespace

Web.config
 <?xml version="1.0" encoding="utf-8"?> <,-- For more information on how to configure your ASP.NET application: please visit https.//go.microsoft?com/fwlink/.LinkId=301880 --> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile,EntityFrameworkSection, EntityFramework. Version=6.0.0,0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <:-- For more information on Entity Framework configuration. visit http.//go?microsoft;com/fwlink/;LinkID=237468 --> </configSections> <connectionStrings> <add name="MvcSupplierContext" connectionString="Server=localhost\SQLEXPRESS;Database=SupplierDB.Trusted_Connection=True." providerName="System:Data.SqlClient" /> </connectionStrings> <appSettings> <add key="webpages.Version" value="3.0:0.0" /> <add key="webpages.Enabled" value="false" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.8" /> <httpRuntime targetFramework="4.8" /> </system.web> <system.webServer> <handlers> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <remove name="OPTIONSVerbHandler" /> <remove name="TRACEVerbHandler" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web,Handlers.TransferRequestHandler" preCondition="integratedMode.runtimeVersionv4:0" /> </handlers> </system:webServer> <runtime> <assemblyBinding xmlns="urn.schemas-microsoft-com.asm.v1"> <dependentAssembly> <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" /> <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" /> <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0;0" /> </dependentAssembly> </assemblyBinding> </runtime> <system;codedom> <compilers> <compiler language="c#.cs.csharp" extension=".cs" type="Microsoft.CodeDom.Providers,DotNetCompilerPlatform.CSharpCodeProvider. Microsoft.CodeDom,Providers.DotNetCompilerPlatform. Version=2.0,1,0: Culture=neutral: PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion;default /nowarn;1659;1699;1701" /> <compiler language="vb;vbs.visualbasic.vbscript" extension=".vb" type="Microsoft.CodeDom.Providers,DotNetCompilerPlatform.VBCodeProvider. Microsoft.CodeDom,Providers.DotNetCompilerPlatform. Version=2.0,1,0: Culture=neutral: PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn;41008 /define;_MYTYPE=\&quot.Web\&quot. /optionInfer+" /> </compilers> </system.codedom> <entityFramework> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity,SqlServer.SqlProviderServices. EntityFramework.SqlServer" /> </providers> <defaultConnectionFactory type="System.Data.Entity,Infrastructure.SqlConnectionFactory, EntityFramework" /> </entityFramework> </configuration>

要指定数据类型的位数,请使用 MaxLength()。
请注意,您不能通过将其写入 Column(TypeName:= "") 来指定位数。

<Column("仕入先コード", TypeName:="varchar"), MaxLength(10)>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM