错误 40 edmx 文件 MVC:类型 decimal(18,0) 未使用命名空间或别名限定
本文关键字:未使用 命名空间 别名 文件 edmx MVC decimal 类型 错误 | 更新日期: 2023-09-27 18:36:20
我对MVC概念很陌生。我正在使用Microsoft Visual Studio Express 2013 for Web和SQL Server LocalDb v11。到目前为止,我没有遇到任何问题。但后来我将数据库中的价格字段从实数更改为十进制(18,0)。我收到有关 edmx 文件的错误:
Error 40: The Type decimal(18,0) is not qualified with a namespace or alias. Only primitive types can be used without qualification.
我已经尝试在我的 edmx 文件中使用类型"十进制"和 int(只是为了看看它是否有效),但仍然出现相同的错误。
我很欣赏每一个答案。
数据库部分:
CREATE TABLE [dbo].[Item] (
[Id] INT NOT NULL,
[DepartmentId] INT NOT NULL,
[Name] NVARCHAR (50) NOT NULL,
[Description] NVARCHAR (MAX) NOT NULL,
[Price] DECIMAL NOT NULL,
[Quantity] INT NOT NULL,
[AuthorId] INT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Item_ToDepartment] FOREIGN KEY ([DepartmentId]) REFERENCES [dbo].[Department] ([Id]),
CONSTRAINT [FK_Item_ToAuthor] FOREIGN KEY ([AuthorId]) REFERENCES [dbo].[Author] ([Id])
);
型号类别:
namespace WebStore.Models
{
using System;
using System.Collections.Generic;
public partial class Item
{
public Item()
{
this.Cart = new HashSet<Cart>();
}
public int Id { get; set; }
public int DepartmentId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
public Nullable<int> AuthorId { get; set; }
public virtual Author Author { get; set; }
public virtual Department Department { get; set; }
public virtual ICollection<Cart> Cart { get; set; }
}
}
以及 edmx 文件中我收到错误 40 的部分:
<EntityType Name="Item">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Int32" Nullable="false" />
<Property Name="DepartmentId" Type="Int32" Nullable="false" />
<Property Name="Name" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
<Property Name="Description" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" Nullable="false" />
<Property Name="Price" Type="decimal(18,0)" Nullable="false" />
<Property Name="Quantity" Type="Int32" Nullable="false" />
<Property Name="AuthorId" Type="Int32" />
<NavigationProperty Name="Author" Relationship="Self.FK_Item_ToAuthor" FromRole="Izdelek" ToRole="Author" />
<NavigationProperty Name="Department" Relationship="Self.FK_Item_ToDepartment" FromRole="Izdelek" ToRole="Departmetn" />
<NavigationProperty Name="Cart" Relationship="Self.FK_Cart_ToItem" FromRole="Izdelek" ToRole="Cart" />
</EntityType>
如果您使用的是十进制,请尝试使用大写字母 D 指定类型,如 edmx 文件的edmx:ConceptualModels
部分中的Type="Decimal" Precision="18" Scale="0"
。edmx:StorageModels
部分应该可以Type="decimal" Precision="18" Scale="0"
.