Can I tell EntLib to ignore a property in my business object when call ExecuteSprocAccessor?
Let's say 开发者_StackOverflow中文版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?
You can do this when you create the mapper. Basically, something like this:
var results = db.ExecuteSprocAccessor("some_sproc",
MapBuilder<MyTargetType>.MapAllProperties()
.DoNotMap("SomethingThatDoesntMatch")
.Build(),
param1, param2, param3);
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.
精彩评论