More in this section

Forums / Developing with Sitefinity / How to create and run a Nolics query?

How to create and run a Nolics query?

5 posts, 0 answered
  1. John
    John avatar
    61 posts
    Registered:
    08 Jun 2012
    01 Sep 2009
    Link to this post
    Hello,

    We are trying to extend the TelerikMembershipProvider by adding methods for retrieving User information using a Nolics query. The following code is located in our App_Code folder (though I've tried it in a separate assembly as well), and we keep getting the "The query <query name> has not been registered. Use DataConnection.Initialize or DataConnection.RegisterAssembly to register an assembly." error on the "LoadAll" line (line 4).

    Code:
    1 using System; 
    2 using System.Collections.Generic; 
    3 //using System.Linq; 
    4 using System.Web.Security; 
    5 using System.Web; 
    6  
    7 using Telerik.DataAccess.AspnetProviders; 
    8 using Nolics.ORMapper.Base; 
    9 using System.Reflection; 
    10  
    11 namespace RNA.DataAccess.AspnetProviders 
    12
    13  
    14     /// <summary> 
    15     /// Customized Membership Provided for RNA Agent Website 
    16     /// </summary> 
    17     public class RNAMembershipProvider : Telerik.DataAccess.AspnetProviders.TelerikMembershipProvider 
    18     { 
    19         public RNAMembershipProvider() : base() 
    20         { 
    21         } 
    22  
    23         public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) 
    24         { 
    25  
    26             Assembly executingAssembly = Assembly.GetExecutingAssembly(); 
    27             DataConnection.Initialize(false, executingAssembly); 
    28  
    29             Assembly baseAssembly = Assembly.GetAssembly(typeof(Telerik.DataAccess.AspnetProviders.UserMetaInfo)); 
    30             DataConnection.RegisterAssembly(baseAssembly); 
    31  
    32             base.Initialize(name, config); 
    33         } 
    34  
    35         /// <summary> 
    36         /// Returns a User for the given LifePRO NameID value. 
    37         /// </summary> 
    38         /// <param name="nameId"></param> 
    39         /// <returns></returns
    40         public User GetUserByNameID(int nameId) 
    41         { 
    42  
    43             Query<UserMetaInfo> userMetaInfoQuery = new Query<UserMetaInfo>(); 
    44             userMetaInfoQuery.AndCondition("PropertyName", QueryCondition.EQ, "LPNameID"); 
    45             userMetaInfoQuery.AndCondition("Integer", QueryCondition.EQ, nameId); 
    46  
    47             userMetaInfoQuery.LoadAll(); 
    48  
    49             User user = null
    50  
    51             if (userMetaInfoQuery.Count > 0) 
    52             { 
    53                 user = userMetaInfoQuery[0].Parent.User_lnk; 
    54             } 
    55  
    56             return user; 
    57         } 
    58     } 
    59

    I have been unable to find any detailed instructions regarding how to create and use a Nolics query in our code. I was able to find a posting that prompted me to add the "Initialize" and "RegisterAssembly" entries in the class initialization, but they did not help.

    BTW, I have changed the web.config <membership> provider entry to point to this new class.

    Can anyone please tell me where my code is incorrect, or what needs to be done to be able to query the UserMetaInfo objects?

    Regards,
    John Gassman
    Workstate
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    02 Sep 2009
    Link to this post
    Hi John,

    Thank you for using our services.

    Have you considered taking a look at the Nolics examples in our Developer Manual? If you have not please take a look at the following tutorials:
    Implementing Data Access with Nolics.NET
    Creating Nolics.NET Data Access Project for Custom Module

    Both of those tutorials have example on how to define your queries for accessing data using Nolics.Net. Please take a look at them and come back to us if you have more questions.

    Greetings,
    Rado
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. John
    John avatar
    61 posts
    Registered:
    08 Jun 2012
    02 Sep 2009
    Link to this post
    Hello Rado,

    Thank you. Yes, I have looked at those pages. There is no mention of the particulars of Nolics in there - specifically registering or initializing assemblies. Also, all examples I have seen are "self contained". That is, the dbclass objects and classes that access them are all in the same assembly. What I need to do is create a Nolics query using your existing UserMetaInfo object from Telerik.DataAccess.AspnetProviders. I think I know what the correct syntax is for creating the Dynamic Query (I posted my code in my initial posting), but the problem is that Nolics throws an error whenever I try to get results from the Query.

    It seems that either it is not possible to create a Nolics query in the main application (in a class in the App_Code folder) that references objects in a DLL, or I am missing some step in my code. I have also tried created a separate class library project with basically the same code in it just in case the Nolics framework did not work correctly from the App_Code folder, but the results are the same.

    The Sitefinity developer guide, and Nolics own documentation have little or no information on the error we are receiving when calling the LoadAll() method of the query:

    Nolics.ORMapper.Base.NolnetException: The query Query`1 has not been registered. Use DataConnection.Initialize or DataConnection.RegisterAssembly to register an assembly. 


    All help is appreciated!

    Regards,
    John Gassman
    Workstate
  4. John
    John avatar
    61 posts
    Registered:
    08 Jun 2012
    02 Sep 2009
    Link to this post
    OK, I think we have figured this out. One aspect that we had been overlooking was the first parameter of the DataConnection.Initialize method. This parameter specifies whether or not to have Nolics connect to the data source. We had been setting this to false, but were not manually establishing the connection (we assumed the base class - TelerikMembershipProvider - was already doing that).

    So, our derived class Initialize now looks like this:
    1 private OdbDataProvider _odbProvider; 
    2  
    3 public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) 
    4
    5     String connectionString = config["connectionStringName"]; 
    6     DataConnection.Initialize(false, base.GetType().Assembly); 
    7              
    8     _odbProvider = NolicsHelper.SetConnection(connectionString); 
    9  
    10     Assembly dataAccessAssembly = Assembly.GetAssembly(typeof(UserMetaInfo)); 
    11     DataConnection.RegisterAssembly(dataAccessAssembly); 
    12  
    13     base.Initialize(name, config); 
    14
    15  

    Adding the code at line 8 seems to have done the trick.

    Hopes this helps somebody else!

    Regards
    John Gassman
    Workstate
  5. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Sep 2009
    Link to this post
    Hi John,

    Were are happy to see that you have managed to sort this issue out. And appreciate it a lot that you have shared your approach to the community.

    If you feel that you need more assistance in working with Sitefintiy, please feel free to contact us.

    Kind regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
5 posts, 0 answered