EntLib5 DAAB Accessors and Interfaces

Topics: Data Access Application Block, Pre-release discussions
Jan 2, 2010 at 4:41 AM

I hope this is the place to post this.

I have been doing some playing around and trying to use EntLib 5 and the new accessors that are available.  I am trying to do this: 

   1: var db = EnterpriseLibraryContainer.Current.GetInstance<Database>();
<!--CRLF-->
   2: var salesperson = db.ExecuteSprocAccessor<ISalesPerson>("[Sales].[SalesPerson_GetByBusinessEntityId]", new SalesPersonFactory(), 288).SingleOrDefault();
<!--CRLF-->

The issues that I am having is my factories uses interfaces and it looks like the accessors require that the classes be passed in have constructors.  I can understand this since the factories are optional.  I guess I have 2 thoughts:

  1. Could you not use Unity to create the instance of the type being passed in?  That way I could define the mapping for ISalesPerson within Unity.  I am not an expert at unity and not sure what challenges this would add.  I use unity to create my entities now and I just use a wrapper Dependency.Resolve(ISalesPerson).
  2. If the type being passed in is ISalesPerson and a factory isn't provided, throw an exception if it doesn't implement a parameterless constructor.  i think it would be pretty understandable if you didn't pass something in that wasn't constructable to expect an exception.

I would be interested to know if you all have considered this and maybe share some of your thoughts. I got this working for me by taking the latest code for EntLib5 and commenting out the "where TResult : new()" in a few places.  Everything seems to work ok without this in there in both the scenario where I don't provide a constructor and where I do.

Thanks

jeff

Jan 5, 2010 at 1:05 AM
Edited Jan 6, 2010 at 9:39 AM

[updated]

Ok, I looked into the code but I think the EntLib team could provide you a better insight.  I'll redirect this to them.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jan 23, 2010 at 8:09 PM

Any more news on this?  I am writing a code generator, ORM around EntLib 5 and I am going to really need to be able to send in an Interface to the EntLib.  I am wrapping a generic repository around EntLib and it's all Unity and Interface based.  Will be very helpful to me to take advantage of the new Accessor methods.

Thanks again for forwarding along.  Beta is getting close so I am hoping they consider this.

jeff

Jun 25, 2010 at 7:06 AM

As of the entlib 5 release, this wasn't implemented.

Aug 7, 2010 at 4:33 AM

I'm having the same problem trying to use an interface for the ExecuteSprocAccessor<interface>

This is in a n-tier where the BO uses the interface and calls a DA. Then the DA uses the interface to get the object from the BO.

This was used to stop circular reference.

Any suggestions?

Aug 7, 2010 at 5:01 AM

Accessors were designed to be used for simple data transfer objects, not full-bore business entities. As such they're fairly limited around things like interfaces. If that's what you want to do, accessors are probably not the functionality you want. Have you considered a more powerful ORM solution instead?

We deliberately designed it this way so people wouldn't say we're building an ORM into Entlib; there's many excellent players in this space already, and we don't need to waste our limited time adding nothing but more noise to it.