ISimpleDomainObjectFactory

Jul 24, 2008 at 4:18 PM
I've a problem with FindOne method. This method use "ISimpleDomainObjectFactory" as domainObjectFactory instead of  "IDomainObjectFactory" used on Find method.

In the factory class with IDomainObjectFactory interface I can use the "reader" for get value from field (ex: reader.GetOrdinal("CustomerID")).

How can I do the same thing in the factory class with then ISimpleDomainObjectFactory interface where there is no "reader".

Thank you and sorry for my bad english

Roberto (I)
Developer
Jul 29, 2008 at 9:01 PM
Hi,

I created the ISimpleDomainObjectFactory as an alternative to using a cursor for retrieving a single row in the database.  This interface expects you to pass in an Enterprise Library Database object.  Your stored procedure needs to specify OUT or IN/OUT parameters for each parameter that would otherwise have been columns in the cursor.  Then, in your object factory, perform a (type_cast)db.GetParameterValue(dbCommand, "parameterName").  For example:
 
Int32 customerId = (Int32)db.GetParameterValue(dbCommand, "P_CUST_ID");

See the Enterprise Library Data Access Application Block documentation for more information.

Cheers,

Philippe
Aug 6, 2008 at 1:55 PM
Hi rcorra68,

I have a problem with generated code for the DataAccess Layer - BusinessEntities.<Entity>RepositoryArtifacts.
for example the get method which is implementing interface ISimpleDomainObjectFactory says :

Error 94 'OnlineShop.DataAccess.BusinessEntities.MailUsersRepositoryArtifacts.GetMailUsersByIDFactory' does not implement interface member 'Microsoft.Practices.Repository.ISimpleDomainObjectFactory<OnlineShop.BusinessEntities.MailUsers>.Construct(Microsoft.Practices.EnterpriseLibrary.Data.Database, System.Data.Common.DbCommand)' C:\Projects\OnlineShop\ResourceAccess\OnlineShop.DataAccess\BusinessEntities.MailUsersRepositoryArtifacts\GetMailUsersByIDFactory.cs 18 27 OnlineShop.DataAccess

And Code for that is:

namespace OnlineShop.DataAccess.BusinessEntities.CustomersRepositoryArtifacts
{
    /// <summary>
    /// Construct a Customers object from OUT and IN/OUT parameters.
    /// </summary>
    internal sealed class GetCustomersByEMailFactory : ISimpleDomainObjectFactory<Customers>
    {
        public Customers Construct(Database db, DbCommand command)
        {
   Customers customers = new Customers();
 
 customers.Address= (String)(db.GetParameterValue(command, "Address") );

 customers.City= (String)(db.GetParameterValue(command, "City") );

 customers.Company= (String)(db.GetParameterValue(command, "Company") );

 customers.DateCreated= CastDBNull.To<DateTime>(db.GetParameterValue(command, "DateCreated") , DateTime.MinValue);

 customers.DateUpdated= CastDBNull.To<DateTime>(db.GetParameterValue(command, "DateUpdated") , DateTime.MinValue);

 customers.EMail= (String)(db.GetParameterValue(command, "EMail") );

 customers.FirstName= (String)(db.GetParameterValue(command, "FirstName") );

 customers.ID= CastDBNull.To<Guid>(db.GetParameterValue(command, "ID") , // TODO: GetCastDBNullDefault(string clsType) could not determine default value for clsType = Guid);

 customers.LastName= (String)(db.GetParameterValue(command, "LastName") );

 customers.Phone= (String)(db.GetParameterValue(command, "Phone") );

 customers.SubscriptionForNewProducts= CastDBNull.To<Boolean>(db.GetParameterValue(command, "SubscriptionForNewProducts") , false);

          
   return customers;
        }
    }
}

What to do to Build the project?

Jan 13, 2009 at 11:40 PM
Hi.

I am also getting this - I get it for all my factory classes - select, update, delete, insert.
The interface has definately been implemented though and there doesn't appear to be any coding errors.

Any assistance in how to resolve this would be appreciated - even if I implement interface explicitly it doesn't help, I just get another error:

'ISelectionFactory<...>.ConstructSelectCommand' in explicit interface declaration is not a member of interface

VS2008
Win XP SP2
SQL Server 2005
Have tried RepositoryFactory-30190 and RepositoryFactory-29184 but get the same error.

many thanks


Developer
Jan 14, 2009 at 5:26 PM
The Microsoft.Practices.Repository assembly has been updated.  The assembly reference is likely pointing to an old version of that assembly.  Be sure to update your project's reference to version 2.0.0.0 of this assembly (it should be located in the main folder of the factory's installation target folder).
Jan 15, 2009 at 6:04 AM
Hi.

Just letting you know that with help from Luis, I found out that I was using Enterprise Library 4.0 and repository was only using 3.1.  I have sent a copy to Luis with updates to Ent Lib 4.0 and he can post if he wants to. Once I built and re-installed, the problem went away.
Thanks for your help all.