【发布时间】:2020-09-30 17:42:07
【问题描述】:
我正在尝试上传多张图片。所以我创建了一个模型来存储多个图像。我创建了一个属性public List<string> Photos { get; set; }然后当我为创建数据表进行迁移时,我收到了这个错误:
The property 'Shop.Photos' could not be mapped, because it is of type 'List<string>' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
这是我的模型
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
namespace ShopingCenter.Models
{
public class Shop
{
public int Id { get; set; }
[Required]
[Display(Name = "product name")]
public String Name { get; set; }
[Required]
public int Price { get; set; }
public String Image { get; set; }
public List<string> Photos { get; set; }
[Required]
public int Quantity { get; set; }
[Required]
public bool IsAvailable { get; set; }
[Display(Name = "Category")]
public int? CategoryTypeId { get; set; }
[ForeignKey("CategoryTypeId")]
public Category Category { get; set; }
[Display(Name = "SubCategory")]
public int? SubCategoryTypeId { get; set; }
[ForeignKey("SubCategoryTypeId")]
public SubCategory SubCategory { get; set; }
}
}
我不明白问题出在哪里。我应该改变什么来上传多个文件?我是初学者。请帮忙。
【问题讨论】:
-
字符串不是照片。字符串应该是什么样的?
-
@GertArnold 错误来自公共列表
Photos { get;放; } ...名称列表。 -
@GertArnold Gert...我看到您有 EF 的历史...并且想知道您是否可以提供一个好的教程资源...我很适合找到任何... TIA。
标签: c# asp.net-core entity-framework-core asp.net-core-mvc