Create new Updatefactory method

Oct 26, 2007 at 3:29 PM
I have been using the reposotiry Factory for about a month now, I am trying to see how I can modify the generated code to include a second update method to the Update Factory generated class, for a given entity. Running through the wizard I can only pick one stored procedure to update a given business entity.

However now I need to use a second Stored procedure to update the same business entity under different conditions updating different columns.

If run the wizard again I will loose my initial generated files, so, is there a way to make an update to generated UpdateFactory for a given business entity.

Do I have to hand code a second UpdateFactory and use it as input to the base.Save method; the second UpdateFactory will use the second Stored Procedure

Will this approach work?
Or
Would it be more prudent to update my current stored procedure to be able to handle both typed of updates.

Jawahar
Oct 27, 2007 at 1:56 AM

jawahar wrote:
I have been using the reposotiry Factory for about a month now, I am trying to see how I can modify the generated code to include a second update method to the Update Factory generated class, for a given entity. Running through the wizard I can only pick one stored procedure to update a given business entity.

However now I need to use a second Stored procedure to update the same business entity under different conditions updating different columns.

If run the wizard again I will loose my initial generated files, so, is there a way to make an update to generated UpdateFactory for a given business entity.

Do I have to hand code a second UpdateFactory and use it as input to the base.Save method; the second UpdateFactory will use the second Stored Procedure

Will this approach work?
Or
Would it be more prudent to update my current stored procedure to be able to handle both typed of updates.

Jawahar


The current code will not overwrite your existing code, so I'm not sure what the issue is.

Regenerate the repository class, add an operation that calls your second sproc, and everything should just work.

-Chris
Oct 29, 2007 at 4:47 PM
When I re-generate the Repository classes for the entity and choose the second Update stored procedure I loose all the code that was initally generated for the first update stored procedure. I need to use both update stored procedures in different stiutations.

The second update stored procedure is more like "re-set all" in my application. ( I am working on a messaging application where I need to re-set queue status to initial when a certain condition occurs)

Does the Repository factory have options when generating repository classes from entities for "Update Many" instead of only "Update One"?

Is such an option available in the official release at Codeplex

Jawahar


ctavares wrote:

jawahar wrote:
I have been using the reposotiry Factory for about a month now, I am trying to see how I can modify the generated code to include a second update method to the Update Factory generated class, for a given entity. Running through the wizard I can only pick one stored procedure to update a given business entity.

However now I need to use a second Stored procedure to update the same business entity under different conditions updating different columns.

If run the wizard again I will loose my initial generated files, so, is there a way to make an update to generated UpdateFactory for a given business entity.

Do I have to hand code a second UpdateFactory and use it as input to the base.Save method; the second UpdateFactory will use the second Stored Procedure

Will this approach work?
Or
Would it be more prudent to update my current stored procedure to be able to handle both typed of updates.

Jawahar


The current code will not overwrite your existing code, so I'm not sure what the issue is.

Regenerate the repository class, add an operation that calls your second sproc, and everything should just work.

-Chris

Oct 29, 2007 at 11:16 PM

jawahar wrote:
When I re-generate the Repository classes for the entity and choose the second Update stored procedure I loose all the code that was initally generated for the first update stored procedure. I need to use both update stored procedures in different stiutations.

The second update stored procedure is more like "re-set all" in my application. ( I am working on a messaging application where I need to re-set queue status to initial when a certain condition occurs)

Does the Repository factory have options when generating repository classes from entities for "Update Many" instead of only "Update One"?

Is such an option available in the official release at Codeplex

Jawahar



Ok, now I think we're getting into "bug in the package" territory.

Could you do me a favor and post the exact steps you're following (exactly which menu items you're selecting, etc) that causes the previously generated code to be overwritten? It shouldn't be doing that.

-Chris
Oct 30, 2007 at 7:45 PM
Thanks Chris for responding
I have a VS 2005 solution that is used for messaging.

I have a BusinessEntities project which has project responsibility of "BusinessEntity"

I have a DataAccess project which has project responsibility of "Data Access and Host Project"

I create the Business Entities by
Right Click BusinessEntities project --> Repository Factory -->Create Business Entities From Database --> follow the Wizard --> specify the ConnedtionString Name --> select the tables in the next step

I create the Repository Classes From Business Entities by
Right Click DataAccess project --> Repository Factory --> Create Repository Class From business Entities --> follow the Wizard.
I make sure the Host Project is correct , the Connection String name is correct, in the next step I make sure Business Project is correct.
Then select the appropriate Entity--> on next screen use the Add button to specify the type, which I typically use "Get Many" , "insert One", Update One" Complete the mapping for each and then finish

Later if I need to add a new stored proc like an update Many (reset some failed messages)
I do the following:
Right Click DataAccess project --> Repository Factory --> Create Repository Class From business Entities --> follow the Wizard.
select the appropriate Entity--> on next screen use the Add button to specify the type, which I typically use the Update One but I make sure I select the new stored Proc, then complete the wizard

At this point the Interface for the Business Entity wihch previously had a Generic List,, Insert and Save methods now only has a save method and the Repository class which inherits from Repository and the entity interface only has the Save method and the Update Factory is also changed to use the new stored proc

The previously generated Factory classes for Insert and select are still there in the project.


I hope this is clear, let me know if need to send you any concerete examples.


questions
Could this be because I am trying to generete a factory update that is an Update Many insetead of Update one?
I am also not using the Official Oct release - should I be using that (I think I am using an early Sept 07 release)?

Thanks
Jawahar


ctavares wrote:

jawahar wrote:
When I re-generate the Repository classes for the entity and choose the second Update stored procedure I loose all the code that was initally generated for the first update stored procedure. I need to use both update stored procedures in different stiutations.

The second update stored procedure is more like "re-set all" in my application. ( I am working on a messaging application where I need to re-set queue status to initial when a certain condition occurs)

Does the Repository factory have options when generating repository classes from entities for "Update Many" instead of only "Update One"?

Is such an option available in the official release at Codeplex

Jawahar



Ok, now I think we're getting into "bug in the package" territory.

Could you do me a favor and post the exact steps you're following (exactly which menu items you're selecting, etc) that causes the previously generated code to be overwritten? It shouldn't be doing that.

-Chris


Developer
Nov 1, 2007 at 1:42 PM
As a quick workaround, the Repository Factory creates partial classes for each repository, so you could create another partial class for the repository in question and add the custom update method to it. This would allow you to get all the benefits of the code generation and assurance that the custom methods you add to each Repository Class do not get overrriden if re-generated. This is the same strategy employed by most code generators to allow you to add custom properties and methods to your classes.

Hope this helps,

Dave

_______________________________

David Hayden
Microsoft MVP C#
Nov 1, 2007 at 8:09 PM
Dave
Thanks for the suggestion; I followed your suggestion and it is working.

One thing I have noticed in the generated classes wihch inherit from the Repository class the methods available are:

Find (returns a List<TDomainObject>); FindOne (returns a TDomainObject).

The Add, Remove and Save methods all return void, how can this be changed to include methods that have some some return values like number of rows updated, which my stored procs do but I cannot see a way to get the return Command object back to look at return parameters.

If this is an enhancement to the current code base would this be something that I could add as a contribution to the Repository Project.

Jawahar




DavidHayden wrote:
As a quick workaround, the Repository Factory creates partial classes for each repository, so you could create another partial class for the repository in question and add the custom update method to it. This would allow you to get all the benefits of the code generation and assurance that the custom methods you add to each Repository Class do not get overrriden if re-generated. This is the same strategy employed by most code generators to allow you to add custom properties and methods to your classes.

Hope this helps,

Dave

_______________________________

David Hayden
Microsoft MVP C#

Dec 13, 2007 at 4:27 PM
Hi,

You mentioned that the Repository Factory creates partial classes for each repository, however, when I run it I get regular classes! I've gone into the template and amended it so that I do now get partial classes but I'm assuming that I shouldn't have to do this. Any ideas what might be wrong with my set up.

I'm running VS 2005 SP1 and I installed the latest release of RF.

Many thanks

Mat


DavidHayden wrote:
As a quick workaround, the Repository Factory creates partial classes for each repository, so you could create another partial class for the repository in question and add the custom update method to it. This would allow you to get all the benefits of the code generation and assurance that the custom methods you add to each Repository Class do not get overrriden if re-generated. This is the same strategy employed by most code generators to allow you to add custom properties and methods to your classes.

Hope this helps,

Dave

_______________________________

David Hayden
Microsoft MVP C#