我对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文件中使用'decimal'类型,也尝试使用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>
答案 0 :(得分:3)
如果您使用十进制尝试在edmx文件的Type="Decimal" Precision="18" Scale="0"
部分中指定类似edmx:ConceptualModels
的大写字母D的类型。使用edmx:StorageModels
时,Type="decimal" Precision="18" Scale="0"
部分可以正常使用。