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: Not possible to load DropDownList on FormView from code behind? ....and I had many additional problems after that.
因此,我是在关于“自动交换器”的一篇文章上,我非常了解这一点,但从该文章的音响来看,这might是一个可行的替代办法,可替代双向数据,对一个域实体表示反对的一种形式? 根据我的理解,自动估价器基本上在命名公约上运作,因此,它将寻找来源和目的地的对应名称。
因此,基本上,我拥有所有拥有财产的领域实体(即:个人)(第一民族、上尼亚美、地址等)。
因此,如果这样做的话,一个人就只能完全摆脱曲解的表态控制,这只是一个具有约束力的、不具约束力的网络格式。
(我知道,当然,如果我使用MVC I,那就没有这些问题。)
<Caveat 1: AutoMapper必须了解每个控制项目的适当property name 类型 (控制权本身与实体的财产相同,但行为取决于控制类型),即:
Person.FirstName --> form.FirstName..Text
Person.Country --> form.Country.SelectedValue
Person.IsVerified --> form.IsVerified.Checked
......因此,必须先令对表格进行控制,确定其类型,然后在域标和网络格式控制之间对控制的适当财产进行负荷/卸载。
<Caveat 2: Nested Controls - totrice matters further, if one could adopt a webform to AutoMapper (我不知道你是否能够做到),来文方/目的地控制不一定是网络版的根基,因此,人们必须能够对通过网络格式进行的所有儿童控制(这是一件易事)的重新搜索,并退回所有有效的国际调查要素类型。
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?
任何想法?
Update
从我刚才看,这似乎与一条道路一样,很可能要走下去:
http://automapper.codeplex.com/wikipage?title=Custom%20Type%20Converters&referringTitle=Home
http://msdn.microsoft.com/en-us/library/ayybcxe5%28VS.71%29.aspx