Welcome to the CodeSmith Community!

DALC Templates

File Share

A description has not yet been added to this group.

DALC Templates

  • rated by 0 users
  • This post has 9 Replies |
  • 3 Followers
  • Here is a pair of templates I have been using lately. It produces what I call DALC (Data Access Layer Components) based on a SQL database.
     
    DALC.cst is basically an advanced form of BusinesObject.cst combined with CSharpTypedCollection.cst. The way I use it is with the CodeSmithGenerator custom tool in VS.NET. Create an XML file like the one used in the CSharpCodeGeneratorSample and let 'er rip.
     
    The second template is StoredProcedures.cst. DALC.cst is currently dependent on the existence of a set of stored procedures for each table. You could easily change DALC.cst to remove this dependency, but I like having SPs as a layer between my code and the tables.
     
    There are a couple of issues with StoredProcedures.cst that I haven't solved yet. (e.g. It doesn't like text columns.) If someone fixes this, please repost it. I've just been fixing it in the generated T-SQL when I need to.
     
    Enjoy!
     

    Post Edited By Moderator (ejsmith) : 6/11/2003 11:15:22 PM GMT

    --Peter
  • Wow... today must be template day!   smilewinkgrin
     
    Thanks, this looks like a great sample!
     
    Eric J. Smith

    Eric J. Smith
    Founder / CEO
    CodeSmith Tools, LLC

  • One thing for people to note if they intend to use this template:
     
    This code allows you to change the primary key! It was a design decision on the project and so that is why it is there. If your project doesn't want to allow this, update the Save() method. Read the comments and you will see what it is doing.
     
    --Peter
  • Oops. It looks like I uploaded the wrong StoredProcedure.cst file. The INSERT SP that is generated always generates a new key if it is a GUID. I prefer to create my own GUID keys up in the business logic, so when I use these templates I just want INSERT to do what I tell it. :)
     
    Here is an updated StoredProcedures.cst. If anyone finds any other problems, please post here or email me. Thanks.

    Post Edited By Moderator (ejsmith) : 6/11/2003 11:14:56 PM GMT

    --Peter
  • DALC.zip
    Yet another update to my DALC templates. This ZIP file includes a new DALC.cst and a new StoredProcedures.cst.
     
    Do not use the ones posted above! They have problems.

    ERIC: Is there a way to pull the old attachments from the other messages in this thread?

    --Peter
  • Peter,

    I went ahead and edited the posts to remove the old versions. I believe you should have the ability to edit your own posts, no? If so, then you just edit the post, go into the attachment manager and delete the file.

    Eric J. Smith

    Eric J. Smith
    Founder / CEO
    CodeSmith Tools, LLC

  • Sorry for being stupid, but how do I delete files in the attachment manager? I just tried to delete the 1.0.0 version of my CollectionTemplates.zip in the other thread, as per your advice, but I don't see any Delete button and the Delete key doesn't work on the file name.
  • When I open the file manager, it shows the attached files and to the right of the filename there is a Delete link. Maybe you have to be an admin for this to work?

    Eric J. Smith

    Eric J. Smith
    Founder / CEO
    CodeSmith Tools, LLC

  • Thanks, just found the problem. The attachment manager is actually a pop-up window, but I'm running NetCaptor which transforms pop-ups into browser tabs. Usually this works well but in this particular case, the right side of the window was cut off, obscuring the Delete link. I edited the post using IE6 without NetCaptor and now I could delete the attachment.
  • Hi,
     
    First thanks a lot to share your cool templates!!
     
    I just used it five minutes ago and saw that the line:
     
      /// <summary>
      /// Initialize an new empty Login object.
      /// </summary>
      public <%= GetClassName(SourceTable) %>()
      {
      }
      
      /// <summary>
      /// Initialize a new Login object with the given parameters.
      /// </summary>
      public <%= GetClassName(SourceTable) %>(<%= GetPopulationConstructorParams(SourceTable) %>)
      {
       <% foreach( ColumnSchema column in SourceTable.Columns ) { %>
       this.<%= GetMemberVariableName(column) %> = <%= GetCamelCaseName(column.Name) %>;
       <% } %>
      }
     
    should be like that:
     
      /// <summary>
      /// Initialize an new empty <%= GetClassName(SourceTable) %> object.
      /// </summary>
      public <%= GetClassName(SourceTable) %>()
      {
      }
      
      /// <summary>
      /// Initialize a new <%= GetClassName(SourceTable) %> object with the given parameters.
      /// </summary>
      public <%= GetClassName(SourceTable) %>(<%= GetPopulationConstructorParams(SourceTable) %>)
      {
       <% foreach( ColumnSchema column in SourceTable.Columns ) { %>
       this.<%= GetMemberVariableName(column) %> = <%= GetCamelCaseName(column.Name) %>;
       <% } %>
      }
     
    I know it is a detail, but... ;-)
  • Hello,

    in the application I am just working on I need a business object class not based on a table but on a view. The view consists of the fields of different tables.

    Do you have already thought to extend the template to support view based business objects?
    What are the consequences for the methods (select, insert, update, delete) the business object class could support?

    Thanks for your comment - Martin

    Post Edited (Martin Wegmann) : 6/29/2003 11:34:21 AM GMT

  • Martin,

    Since a view does not have a primary key, I am not sure how you would go about implementing your SIUD methods. Maybe some of the users who requested view support in Schema Explorer can tell us what they are using them for and maybe they have some ideas for your question.

    Eric J. Smith

    Eric J. Smith
    Founder / CEO
    CodeSmith Tools, LLC

  • templates.zip
    Hey thanks for the templates, the were a great help because there are no O/R .net mapping frameworks for .net that are free and stable yet. These templates are good for simple relational databases but for more complex relationships (1:1, 1:M M:M), I think an O/R framework would be better.
    I have made a few changes to these templates if anyone is interested. Now when you do an insert it populates the primary key of the object with the IDENTITY output parameter. I also added support for a ToString() method, and support for specifying a namespace. I also removed the primary key from the insert and update statements because I am just letting sql server do that for me.
    Thanks again,
    Lachlan
  • templates.zip
    I just added support for ORDER BY clauses too.
  • templates.zip
    I found a bug in DALC.cst. After calling the Save() method for the first time the object will be inserted into the DB.
     
    If you try to call Save() again on that object it will do an insert rather than an update. A small change to the Insert() method has fixed the problem.
     
    This bug could also occur when calling Save() on an existing object, I can't really see a need to call Save() twice on an existing object so I didn't fix that.
     
    Lachlan

    Post Edited (lachlanj) : 8/8/2003 1:10:34 AM GMT

  • Page 1 of 2 (22 items) 12