AutoMapper 扁平化了领域模型,但它的作用相反吗? 如果不是,那是什么?

发布于 2024-07-28 23:10:59 字数 326 浏览 4 评论 0原文

我一直在阅读 AutoMapper,因为我之前的一个问题得到了答复 这里

它说 AutoMapper 会展平复杂的域模型,但我需要一些相反的功能。 我需要将视图模型(扁平域模型)连接到复杂的域模型,以便我可以快速将视图模型转换为域模型。

有没有类似于 AutoMapper 的东西,它采用视图模型并使其成为复杂的领域模型?

I've been reading up on AutoMapper because of a response to one of my earlier questions here.

It says that AutoMapper flattens complex domain models, but I need something that does the opposite. I need to wire up my view models (flattened domain models) to the complex domain models so that I can quickly transform a view model into a domain model.

Is there anything similar to AutoMapper that takes a view model and makes it into a complex domain model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

盛夏尉蓝 2024-08-04 23:11:00

你做!。 您创建一个 MapToModel 方法,在其中执行右手/左手编码并将两者同步在一起。

public MyModel MapToModel(MyViewModelForm vmf)
{
  //new up MyModel model;
  model.foo = vmf.foo;

  return model;
}

如果应用程序能够自行编码,我们究竟会以什么为生......?

You do!. You create a MapToModel method where you do the right-hand/left-hand coding and sync the two together.

public MyModel MapToModel(MyViewModelForm vmf)
{
  //new up MyModel model;
  model.foo = vmf.foo;

  return model;
}

If applications coded themselves, what exactly would we do for a living...?

无声静候 2024-08-04 23:11:00

不一定,因为它必须非常传统才能有用。 展平时很容易辨别模式,但反过来……自定义逻辑太多了。

Not really, because it would have to be extremely conventional to be useful. It's easy to discern patterns when flattening, but the other way 'round... just too much custom logic.

ゃ懵逼小萝莉 2024-08-04 23:11:00

非常容易使用:

//flatenning
personDto.InjectFrom<FlatValueInjection>(person);

//unflattening
person.InjectFrom<UnflatValueInjection>(personDto);

ValueInjecter 可以做到这一点,而且

//this is just mapping without flattening/unflattening
foo.InjectFrom(bar)

the ValueInjecter does it, and it's quite easy to use:

//flatenning
personDto.InjectFrom<FlatValueInjection>(person);

//unflattening
person.InjectFrom<UnflatValueInjection>(personDto);

and

//this is just mapping without flattening/unflattening
foo.InjectFrom(bar)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文