AutoMapper一个可行的替代使用一个FormView双向绑定? [英] AutoMapper a viable alternative to two way databinding using a FormView?

查看:298
本文介绍了AutoMapper一个可行的替代使用一个FormView双向绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用FormView控件,以便在asp.net web表单双向绑定启动。我喜欢它救了我的每一页上写loadForm和unloadForm程序的麻烦。因此,它似乎当我只使用文本框到处在一开始很好地工作....但,当它来到时开始转换一些人DropDownLists,舆论大输。例如,请参见:
<一href=\"http://stackoverflow.com/questions/2435185/not-possible-to-load-dropdownlist-on-formview-from-$c$c-behind\">http://stackoverflow.com/questions/2435185/not-possible-to-load-dropdownlist-on-formview-from-$c$c-behind
....我只好许多附加后的问题。

I've started using the FormView control to enable two way databinding in asp.net webforms. I liked that it saved me the trouble of writing loadForm and unloadForm routines on every page. So it seemed to work nicely at the start when I was just using textboxes everywhere....but when it came time to start converting some to DropDownLists, all hell broke lose. For example, see: http://stackoverflow.com/questions/2435185/not-possible-to-load-dropdownlist-on-formview-from-code-behind ....and I had many additional problems after that.

所以,我偶然发现在AutoMapper,我所知甚少又一篇文章,但是从它的声音,这的可能的是一个可行的替代双向数据绑定形式到域实体对象?据我了解,基本上AutoMapper上操作命名约定,因此,它会寻找匹配的名称属性(?)的源和目标对象。

So I happened upon an article on AutoMapper, which I know very little about yet, but from the sounds of it, this might be a viable alternative to two-way databinding a form to an domain entity object? From what I understand, AutoMapper basically operates on naming convention, so, it will look for matched names properties(?) on the source and destination objects.

所以,基本上,我有我的所有域实体(即:人)与属性(名字,姓氏,地址等)......我想什么,能够做的就是声明我的ASP控件(文本框, dropdownlists等)与完全相同的名称,并且具有automapper执行装卸。

So, basically, I have all my domain entities (ie: Person) with properties (FirstName, LastName, Address, etc)....what I would like to be able to do is declare my asp controls (textboxes, dropdownlists, etc) with those exact same names, and have automapper do the loading and unloading.

所以,如果这个工作,一个人可能刚刚摆脱被诅咒的FormView控件的全部,这将是对绑定和取消绑定一个WebForm只有一行。

So if this worked, a person could just get rid of the cursed FormView control entirely, and it would be just one line of for binding and unbinding a webform.

(是的,当然,如果我使用MVC我不会有这些问题,我知道)。

(Yes, of course if I was using MVC I wouldn't have these problems, I know).

买者1 :AutoMapper必须知道正确的属性名作为每个控制的类型(控件本身也有同样的ID作为对实体的属性,但该行为将取决于控制型),即:

Caveat 1: AutoMapper would have to know the proper property name for each control type (the control itself would have the same ID as the property on the entity, but the behavior would depend on the control type), ie:

Person.FirstName - > form.FirstName 。文本结果
Person.Country - > form.Country 的SelectedValue 结果
Person.IsVerified - > form.IsVerified 经过

Person.FirstName --> form.FirstName..Text
Person.Country --> form.Country.SelectedValue
Person.IsVerified --> form.IsVerified.Checked

....所以它必须要有智慧找到表单上的控制,确定其类型,然后加载/域对象和表单控制到控制的财产之间的卸载。

....so it would have to have the smarts to find the control on the form, determine its type, and then load/unload between the domain object and the webform control into the proper property of the control.

买者2 :嵌套的控制 - 以问题更加复杂的是,如果一个人的可能的传递网络表单AutoMapper(我还不知道你是否能),源/目标控制不一定在网络表单的根源,所以人们必须能够对通过网络表单执行递归搜索所有子控件(这很容易),返回所有有效的UI元素类型实例的集合。

Caveat 2: Nested Controls - to complicate matters further, if one could pass a webform to AutoMapper (I don't yet know if you can), the source/destination controls are not necessarily in the root of the webform, so one would have to be able to perform a recursive search of all child controls on the passed webform (this is easy), returning a collection of all valid UI element type instances.

买者3 :用户控制的UI元素是不公开 - 在#2,遍历嵌套控件层次结构时,如果使用的是用户控件,不暴露自己的元素包含公开(没有硬编码左右),一个人必须要对当前AutoMapper集合中的每个元素做的FindControl。这其中似乎是一个潜在的因素在于....结果
   一个)的性能可能是非常差(尽管如果一个用户控制被发现,它可能被传递到该队列的后面,并在必要只处理)结果
   b)由一个单独的地图功能中,一个人如何获得参考的所有当前的映射元素的兄弟姐妹的,在目前的映射功能?

Caveat 3: User control UI elements are not public - when traversing the nested control hierarchy in #2, if you are using user controls, which do not expose their contained elements publicly (without hardcoding it so), one would have to do a FindControl for each element in the current AutoMapper collection. This one seems like a potential dealbreaker....
a) performance could be really bad (although if a User Control was found, it could be passed to the back of the queue and only processed if necessary)
b) from within an individual map function, how does one get reference to all the siblings of the current mapped element, in the current mapping function?

任何想法??

从我读过,这似乎是一会可能要往下走的路径:

From what I've read, this seems like the path one would likely have to go down:

<一个href=\"http://automapper.$c$cplex.com/wikipage?title=Custom%20Type%20Converters&referringTitle=Home\" rel=\"nofollow\">http://automapper.$c$cplex.com/wikipage?title=Custom%20Type%20Converters&referringTitle=Home

http://msdn.microsoft.com/en-us /library/ayybcxe5%28VS.71%29.aspx

推荐答案

我觉得你最好的长远解决办法是检查出的WebForms MVP - 它提供了一个的WebForms更好的抽象层,如果你不能切换到一个MVC环境。那么你将有一个更容易地映射,以及获得MVP模式的好处:

I think your best long term solution would be to check out WebForms MVP - it provides a better abstraction layer over WebForms if you can't switch to an MVC environment. You would then have a much easier time mapping, as well as get the benefits of the MVP pattern:

http://webformsmvp.com/

这篇关于AutoMapper一个可行的替代使用一个FormView双向绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆