简体   繁体   English

更新基本属性-ASP.NET MVC- C#

[英]Update base properties - ASP.NET MVC- c#

I have the following code in a model 我在模型中有以下代码

base.Name = instance.Name;
base.SSN = instance.SSN;
base.DateModified = DateTime.Now
base.ClienType = instance.ClientType;

If I add more properties to my base then i have to update my model to update the properties. 如果我向基础添加更多属性,则必须更新模型以更新属性。 Is there an easier way to update the base.properties instead of listing each of them and then updating the same? 有没有更简单的方法来更新base.properties,而不是列出每个属性然后再更新它们? Yes i know i am being lazy 是的,我知道我很懒

我不太确定为什么要这样做,但是您可能想看看AutoMapper-如果双方的属性都相同,则可以自动将一个映射到另一个而无需进行任何实际设置。

You could use Automapper to automatically map where there is a naming convention. 您可以使用Automapper自动映射存在命名约定的位置。

Also beware that things the following would not map as one has one less t 还要注意,以下内容不会映射,因为一个对象少了一个

base.ClienType = instance.ClientType;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM