CodeSmith Community
Your Code. Your Way. Faster!

using ObjectDataSource with NetTiers

Latest post 05-29-2007 3:18 PM by Devhi0000. 48 replies.
  • 08-09-2005 10:29 PM

    using ObjectDataSource with NetTiers

    I've been doing my last project with 2.0, and have been trying to figure out the best way to leverage 2.0 functionality with netTiers.

    As many of you already knew it was difficult to use ObjectDataSources because they were a singleton objects. So really we just needed a default constructor for the sqlprovider entity type.

    So to do this, modify the SqlEntityRepository.cst header to the following.

    ///<summary>
        /// This class is the SqlClient Data Access Logic Component implementation for the <see cref="<%=ClassName%>"/> business entity.
        ///</summary>
        [DataObject]
        public class <%=RepositoryClassName%> : <%=AbstractRepositoryClassName%>
        {
            
            #region Constructors
        
            /// <summary>
            /// Creates a new <see cref="<%=RepositoryClassName%>"/> instance.
            /// </summary>
            public <%=RepositoryClassName%>() : base((NetTiers.Configuration.SqlDataProviderData)Configuration.Current.DataProviderSettings)
            {
            }


    yeah

    Now just use the SqlXXXEntityProvider as your object data type.

    Robert

    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 500
  • 10-04-2005 11:55 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    RE: using ObjectDataSource with NetTiers

    Robert,
    I just thought that I would update this post since things have changed a bit.  The file that you need to modify is SqlEntityProvider.cst.
    ///<summary>
     /// This class is the SqlClient Data Access Logic Component implementation for the <see cref="<%=ClassName%>"/> business entity.
     ///</summary>
     [DataObject]
     public class <%=ProviderName%> : <%=ProviderBaseName%>
     {
      
      #region Constructors
     
      /// <summary>
      /// Creates a new <see cref="<%=ProviderName%>"/> instance.
      /// </summary>
      public <%=ProviderName%>() : base((NetTiers.Configuration.SqlDataProviderData)Configuration.Current.DefaultDataProviderSettings)
      {
      }
    Ben

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 5
  • 10-12-2005 5:33 PM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    RE: using ObjectDataSource with NetTiers

    I'm away from my 2.0 project (side-project at home), but the easiest way to use the ObjectDataSource without changing the templates, you can add code to the ObjectDataSource.ObjectCreating event. It looks something like this if my memory is correct

    e.ObjectInstance = <ProviderNameGoesHere>

    and it works fine. I will update this when I get home with working code

    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 5
  • 10-12-2005 5:41 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    RE: using ObjectDataSource with NetTiers

    That's good to know.  However, is there any reason these changes shouldn't be integrated into the templates?  Granted, you can add extra code, but why do that if you don't have to?  By adding the DataObject attribute, you can use the "Configure Data Source" task, and only see the objects that you can actually use as a source for the ObjectDataSource.  The simpler you can make things, the more adoption you will get from a wider community.
     
    Ben

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 5
  • 10-12-2005 5:51 PM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    RE: using ObjectDataSource with NetTiers

    I agree. It would be nice to use the objectdatasource tag out of the box as long as it doesn't break it for other uses. I was just giving an alternate approach with current version of the templates.
     
    At least with the version I have right now.  Probably out of date.

    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 5
  • 11-21-2005 9:05 AM In reply to

    RE: using ObjectDataSource with NetTiers

    I made a change to the templates as described above and can use the SQLEntityProvider to populate a DetailsView. However, I am having difficulty getting my object to update correctly. There are two problems.

    Some of the items are defined in the DetailsView as Visible = false. This results in the relevant "old" or unchanged fields not being carried through to the Update. For example, I hide a field called UOrgUnitID (int Foreign Key) and the Update crashes with a foreign key error. The old unchanged value is not carried through to the update, the update has "null" in this field.

    Secondly, if I make these fields visible (for example, DateAdded which is a DateTime) the old values seem to be carried through but I get "Cannot convert value of parameter 'AddedDate' from 'System.String' to 'System.DateTime' ". It seems I need to do a cast somewhere but I am not sure where!

    Can anyone help please?

    Brian 

     

    Post Edited (jbfurlong) : 11/21/2005 12:53:10 PM GMT

    • Post Points: 5
  • 11-21-2005 4:30 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    RE: using ObjectDataSource with NetTiers

    Brian,

    I think you will have to use an asp:hiddenfield control to bind the values that you don't want displayed.  As for the conversion error, I would take a look at the ItemUpdating event.  You can drill into the NewValues and OldValues dictionary object to see what values are being passed up to the object.  I suspect that it has something to do with Nulls, which are always a pain.  You can take a look at the Admin Entity templates that I put together (available in the Beta 2 repository).  I have some code in there that (I think) works pretty well with null values.  I use a hashtable to keep track of fields that contain null values and then use that information during the update process.  I wish it were easier, but that was the solution that I came up with.

     

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 5
  • 11-28-2005 11:03 PM In reply to

    • dkisting
    • Not Ranked
    • Joined on 11-21-2005
    • Posts 5
    • Points 140

    RE: using ObjectDataSource with NetTiers

    I have made the change to the template, however I am unsure where or which method to access in order to get the GetAll method. Will I be looking in my middle tier or the data layer? We are talking about the same thing, object datasource with NetTiers, however in the IDE, which method should I be looking at?

    Is there no abstraction and the constructor doesn't seem to be getting called.

    Thanks in advance.

    Dan Kisting
    • Post Points: 5
  • 11-29-2005 2:22 PM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    RE: using ObjectDataSource with NetTiers

    The GetAll methods will be in the SqlXXXProvider in the SqlClient project.

    I had to rebuild the solution for the Configure DataSource Dialog to see the new DataObject Methods

    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 5
  • 11-29-2005 5:37 PM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    RE: using ObjectDataSource with NetTiers

    I'm working on my first asp.net 2.0 app (at least for work).  I found the easiest way was to create an adapter for the repository methods.
    I created an XXXRepositoryAdapter in my app_code folder with a default constructor, then wrapped the methods I needed to make my GridView work,
    [DataObject]
    class XXXRepositoryAdapter{
    public XXXRepositoryAdapter(){}
    public Collection GetAll(){
     return Repository.Provider.GetAll();
    }
    GetBy..
    Update..
    Delete..
    ...
    }
     
    This worked well, I just created the methods that I needed.  Anything more than the basic CRUD, you're probably better off to code it into the ObjectDataSource / Grid events.
     
    I think for long term, we might need to create our own ObjectDataSource control.  I read an article couple of months ago about it, but can't find it now.
     

    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 5
  • 11-29-2005 9:38 PM In reply to

    RE: using ObjectDataSource with NetTiers

    John,

    Are you possibly referring to the subclassing of DataSourceControl?

    Nikhil Kothari has what looks like a great five part introduction to this type of server control development:

    http://www.nikhilk.net/DataSourceControlsSummary.aspx
    • Post Points: 5
  • 11-29-2005 9:44 PM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    RE: using ObjectDataSource with NetTiers

    Yep, that was it. I am bookmarking it now. I seriously googled for 45 minutes to find this again. Thanks.

    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 5
  • 11-29-2005 9:50 PM In reply to

    RE: using ObjectDataSource with NetTiers

    My pleasure! I just discoverred nettiers today and look forward to learning more about it.
    • Post Points: 5
  • 12-02-2005 8:06 PM In reply to

    • rgrama
    • Top 500 Contributor
    • Joined on 12-01-2005
    • Omaha, NE
    • Posts 12
    • Points 325

    RE: using ObjectDataSource with NetTiers

    John,
    How did you implement updates, did you use a foreach on the collection retrieved by GetAll?
    Thanks,
    Radu
    John Teague said...
    I'm working on my first asp.net 2.0 app (at least for work).  I found the easiest way was to create an adapter for the repository methods.
    I created an XXXRepositoryAdapter in my app_code folder with a default constructor, then wrapped the methods I needed to make my GridView work,
    [DataObject]
    class XXXRepositoryAdapter{
    public XXXRepositoryAdapter(){}
    public Collection GetAll(){
     return Repository.Provider.GetAll();
    }
    GetBy..
    Update..
    Delete..
    ...
    }
     
    This worked well, I just created the methods that I needed.  Anything more than the basic CRUD, you're probably better off to code it into the ObjectDataSource / Grid events.
     
    I think for long term, we might need to create our own ObjectDataSource control.  I read an article couple of months ago about it, but can't find it now.
     

    • Post Points: 5
  • 12-03-2005 12:33 AM In reply to

    • jcteague
    • Top 10 Contributor
    • Joined on 03-10-2005
    • Austin, Tx
    • Posts 442
    • Points 10,925

    RE: using ObjectDataSource with NetTiers

    The only requirement for the objectdatasource that is not implemented by the data providers is a default constructor. So just create a class with an empty constructor an add any methods you want to call from the object datasource. In the case of a collection update, do the same thing for the entity wrapper.

    public bool Update(XXXCollection entity){
    return DataRepository.XXXProvider.Update(XXXCollection entity);
    }

    Most of mine just wrap the basic methods and add other methods as I find necessary.

    Thanks, John Teague ------------------------------ Member of the .NetTiers team http://www.nettiers.com ------------------------------

    • Post Points: 5
Page 1 of 4 (49 items) 1 2 3 4 Next > | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems