小编Kol*_*256的帖子

实体类型“List<string>”需要定义主键

获取“实体类型 List<string'> 需要定义主键。” 使用 .NET 6 构建 Web API。

以下是我定义“销售”的模型类:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace SalesAPI.Data
{
    public class SalesItem
    {
     
        [Key]
        [Required]
        public Guid UserID { get; set; }

        [Required]
        [MinLength(5)]
        [MaxLength(75)]
        public String Title { get; set; }  = String.Empty;

        [Required]
        [MinLength(5)]
        public String Description { get; set; } = String.Empty;

        public List<String> Images { get; set; } = new List<String>();

        [Required]
        public DateTime ListingTime { get; set; }

        public String Location { get; set; } = String.Empty; …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

entity-framework-core ×1