我可以告诉 EntLib 在调用 ExecuteSprocAccessor 时忽略业务对象中的属性吗?
假设我有一个具有 5 个属性的业务对象和一个返回 4 列且名称与其中 4 个属性匹配的存储过程。对 ExecuteSprocAccessor 的调用将失败。有没有办法可以用属性标记第五个属性,例如告诉 EntLib 忽略它?
Let's say I have a business object with 5 properties and a sproc that returns 4 columns with names matching 4 of those properties. The call to ExecuteSprocAccessor will fail. Is there a way I can mark the 5th property with an attribute, for example, to tell EntLib to ignore it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在创建映射器时执行此操作。基本上是这样的:
它将按名称将所有参数与结果匹配,但不会将任何内容映射到属性 SomethingThatDoesntMatch。
需要注意的是:通过 MapBuilder 创建结果集映射器有点昂贵,而且它不会自动缓存。如果您在循环中执行此调用,则速度可能会很慢。我建议提前创建映射器并保留它,或者单独创建访问器并保留该访问器。
You can do this when you create the mapper. Basically, something like this:
That'll match all the parameters to results by name, but not map anything to the property SomethingThatDoesntMatch.
Something to be aware of: creating the result set mapper by the MapBuilder is kind of expensive, and it doesn't get cached automatically. If you're doing this call in a loop, it'll probably be slow. I'd recommend creating the mapper ahead of time and holding onto it, or creating the accessor separately and holding onto the accessor.