Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将WebAPI资源模型映射到Web UI模型_C#_Entity Framework Core_Automapper_Blazor_Webapi - Fatal编程技术网

C# 将WebAPI资源模型映射到Web UI模型

C# 将WebAPI资源模型映射到Web UI模型,c#,entity-framework-core,automapper,blazor,webapi,C#,Entity Framework Core,Automapper,Blazor,Webapi,我试图尽可能地解耦我的三层应用程序(数据、API、Web)。 到目前为止,我已经通过使用Automapper(创建的概要文件类等)将数据实体映射到API DTO 数据项目-实体 public partial class BlazorEntity { [Key] public int Id { get; set; } [Column("First Name")] [StringLength(50)]

我试图尽可能地解耦我的三层应用程序(数据、API、Web)。 到目前为止,我已经通过使用Automapper(创建的概要文件类等)将数据实体映射到API DTO

数据项目-实体

    public partial class BlazorEntity
    {
        [Key]
        public int Id { get; set; }
        [Column("First Name")]
        [StringLength(50)]
        public string FirstName { get; set; } = string.Empty;
        [Column("Last Name")]
        [StringLength(50)]
        public string LastName { get; set; } = string.Empty;
        [StringLength(50)]
        public string Address { get; set; } = string.Empty;
    }
API项目-资源模型

    public class BlazorEntityModel
    {
       // public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Address { get; set; }
    }

现在,我的目标是将API的资源模型映射到UI项目上的另一个模型。我是否应该使用类似的方法并使用Automapper在UI和API项目之间进行映射?或者我应该直接在UI项目中使用我的资源模型吗?

这取决于您是否必须操作诸如格式化数据之类的属性,例如使用override-toString函数,例如:返回人名(return$“{FirstName}{”LasName};在类中,那么是的,我将为此使用UI模型,并将API保持为直接POCO。