The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Help with EntitySpaces DAL related methods

Last post 09-16-2008, 10:07 AM by martinmizzell. 29 replies.
Page 1 of 2 (30 items)   1 2 Next >
Sort Posts: Previous Next
  •  08-16-2008, 11:07 AM 10771

    Help with EntitySpaces DAL related methods

    Hi,

     I am trying to complete a data provider for DNN and need to implement the "get" queries which return an IDataReader. That said, I have the query built but it is of type esDynamicQuery and the esDataProvider.ExecuteReader() expects an esDataRequest as a parameter. I don't see an implicit type conversion from esDynamicQuery to esDataRequest so how do I satisfy the requirements of the method? Any code samples to this end would be greatly appreciated.

     Thanks,

     Martin

     

  •  08-16-2008, 11:38 AM 10772 in reply to 10771

    Re: Help with EntitySpaces DAL related methods

    Hi Martin, EntitySpaces is not really a DAL but more a persistence layer. It is used a little differently, however is great for use in DNN. With EntitySpaces you have business objects, these are strongly typed. So when you want a collection of Employees you instantiate an EmployeeCollection type, and you can populate it via our Dynamic Query, or in your custom class for the type. You can bind your controls directly to our objects as they support the proper interfaces. Additionally I believe you will find our dynamic query syntax far superiour to the approach DNN takes. When using EntitySpaces for development on the DotNetNuke framework you can follow all our documentation as setup is exactly the same. The one suggestion we do make is that you use dynamic configuration of your connection string and loader assignment. An example of this configuration setup code can be found here. Hope that clears things up a bit, if not feel free to follow up with additional questions.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
    Filed under:
  •  08-17-2008, 11:14 AM 10775 in reply to 10772

    Re: Help with EntitySpaces DAL related methods

    Hi Scott,

    Please let me clarify: I am actually creating new data providers for the DotNetNuke core to enable it to run on other platforms (MySql, PostgreSQL, etc). I am deriving directly from DotNetNuke.DataProvider and need to be able to call methods on the esDataProvider class, i.e. ExecuteReader(). Would you provide me an example of how to do this?

     

    Thanks! 

  •  08-17-2008, 1:48 PM 10776 in reply to 10775

    Re: Help with EntitySpaces DAL related methods

    Gotcha, have a look at our Special Functions. You can create a method in your custom class that uses ExecuteReader and returns a type of IDataReader.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  08-17-2008, 2:16 PM 10777 in reply to 10776

    Re: Help with EntitySpaces DAL related methods

    Ok, we are getting alot closer :-D.

    In these examples, you are building the t-sql statically.

    In my case, I must build it dynamically depending on the data provider's type. Therefore, I have built an esDynamicQuery object. Is there a way that I can inspect the esDynamicQuery's resulting Sql to use for the special functions?

  •  08-17-2008, 3:13 PM 10778 in reply to 10777

    Re: Help with EntitySpaces DAL related methods

    Martin, I love the idea of what you are doing. Did you know that if you use our DynamicQuery API it is database independent by nature. See this POST. There is also the esUtility class that will let you query as well. Still not quite sure if you are generating business objects with ES, if you are, you can make them work independently. Our unit tests are all done via a single binary against all of our supported databases.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-17-2008, 3:53 PM 10779 in reply to 10778

    Re: Help with EntitySpaces DAL related methods

    Thanks, Mike. I looked at the other post and my question is still outstanding at this point (unless i am missing something obvious). In order to leverage the database agnosticity of ES, I am building my queries dynamically using the esDynamicQuery object. Here is a code snippet:

    public override IDataReader GetAffiliate(int AffiliateId, int VendorId, int PortalID)

    {

    AffiliatesQuery a = new AffiliatesQuery("a");

    VendorsQuery v = new VendorsQuery("v");

    object[] columns = new object[]{ a.AffiliateId,a.VendorId,

    a.StartDate,a.EndDate,a.Clicks,

    a.Cpc,a.Cpa,a.Acquisitions};

    a.Select(columns);

    a.InnerJoin(v).On(v.VendorId == a.VendorId);

    a.Where(

    (a.AffiliateId == AffiliateId & a.VendorId == VendorId));

    return new esUtility().ExecuteReader(a.SqlText or something like that?);

    }

     Thanks again for all of the help!

  •  08-17-2008, 5:05 PM 10780 in reply to 10779

    Re: Help with EntitySpaces DAL related methods

    Martin, just a hint, when you post code use our "Code" button. It's the last toolbar button on the right when editing a post, I'll re-post your code (modified though) then comment.

     

    Code:
    public override IDataReader GetAffiliate(int AffiliateId, int VendorId, int PortalID)
    {
    AffiliatesQuery a = new AffiliatesQuery("a");
    VendorsQuery v = new VendorsQuery("v");

    a.Select(a.AffiliateId,
    a.VendorId,
    a.StartDate,
    a.EndDate,
    a.Clicks,
    a.Cpc,
    a.Cpa,
    a.Acquisitions);
    a.InnerJoin(v).On(v.VendorId == a.VendorId);
    a.Where(a.AffiliateId == AffiliateId & a.VendorId == VendorId);

    AffiliatesCollection collection = new AffiliatesCollection();
    coll.Load(a); // JUST LOAD IT LIKE THIS
    }

     

    Notice how I created an AffiliatesCollection and just called load on it passing in the query. That's It !! 

    Now, assume that you have the same database schema in PostgreSQL, Oracle, and SQL (as do our unit tests). Assume your default connection is SQL, the code above would work perfectly. However, if somebody wanted to run your code on Oracle all they would have to do is change the default connection in the config to Oracle, no changes in your code, the same physical binary would work. There is no reason to yank the raw sql out, however, you can see if it you want to like this after you call load:

    string lastQuery = coll.Query.es.LastQuery;

    Feel free to follow up ...


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-17-2008, 5:32 PM 10781 in reply to 10780

    Re: Help with EntitySpaces DAL related methods

    I don't get it. Now it looks like I have made a call to the database to load a collection and still need to hit the database again for the ExecuteReader() method. In the method above, I have to return an IDataReader.
  •  08-17-2008, 5:35 PM 10782 in reply to 10781

    Re: Help with EntitySpaces DAL related methods

    Ahh, you mean you need IDataReader to work with dnn? Sorry I'm so dense, restate at a high level what you need to do?

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-17-2008, 6:11 PM 10783 in reply to 10782

    Re: Help with EntitySpaces DAL related methods

    return new esUtility().ExecuteReader(a.INeedTheSqlTextHere);

     

    In this statement (an extract from the prior post), a is an instance of esDynamicQuery. However, the ExecuteReader method requires the command text (T-SQL). If I were to leverage your esDataProvider.ExecuteReader() instead of using esUtility, it requires an esDataRequest object as a parameter. So here is the question: 

    How do I take an esDynamicQuery object and use it as the query criteria for an ExecuteReader() method?

  •  08-17-2008, 6:19 PM 10784 in reply to 10783

    Re: Help with EntitySpaces DAL related methods

    Okay, I see (but not sure why you need a reader, is that a dnn thing?). We currently don't support turning a Query into a reader, however, to add it is trivial, if you are really interested in really going after this I can add the ability and cut you a special trial version.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-17-2008, 6:38 PM 10785 in reply to 10784

    Re: Help with EntitySpaces DAL related methods

    I already bought the developer license but yes, this is a dnn thing. I was asking about how to implement the ExecuteReader() method because it is the most pervasive return type in creating a custom DotNetNuke.DataProvider. It looks like I am using the EntitySpaces architecture in a way that has not been previously done. How about I just list the functionalities that I assumed were available  and you tell me if I am mistaken because I certainly don't want to start using the product in a way that it wasn't intended to work...

    -ability to build complex criteria via esDynamicQuery (including stuff like pageSize and pageIndex)

    -pass the built criteria to methods defined on the EntitySpaces.Interfaces.esDataProvider contract  

     

  •  08-17-2008, 6:40 PM 10786 in reply to 10785

    Re: Help with EntitySpaces DAL related methods

    Another major presumption that I made is that you modeled you esDataProvider class after the DotNetNuke.DataProvider class. The methods are almost identical and that is yet another reason why I saw your framework and thought it would be a perfect fit.
  •  08-17-2008, 7:43 PM 10787 in reply to 10785

    Re: Help with EntitySpaces DAL related methods

    -ability to build complex criteria via esDynamicQuery (including stuff like pageSize and pageIndex)

    Yes, PageSize and PageNumber are supported

     

    Code:
    coll.Query.es.PageNumber = 4;
    coll.Query.es.PageSize = 20;

    - pass the built criteria to methods defined on the EntitySpaces.Interfaces.esDataProvider contract
    Yes, I am going to add these methods for you, will contact you in a few days.
     

    EntitySpaces | Twitter | BLOG | Please honor our Software License
Page 1 of 2 (30 items)   1 2 Next >
View as RSS news feed in XML