Ask for A sample about modifying reversemapping.config/app.config

Thread is closed for posting
13 posts, 2 answers
  1. huang
    huang avatar
    10 posts
    Member since:
    Jun 2009

    Posted 24 Jun 2009 Link to this post

    Dear All:

    I Have a question of modifying the .config file. Can I only modifying the .config files without changing business layer coding When I  change the DB schema? Also I want to modify it manually for updating purpose.
    Could someone give me similar samples or instruction about that?


    Thanks In Advance,
    Sincerely,
    Andre'
  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 30 Jun 2009 Link to this post

    Hi huang,

    It is not a problem to update your .config file using reverse mapping wizard or manually as long as it does not confront with the model or schema that you have. The idea is , as you mentioned, not to change the business-logic layer but only the configuration and persistent classes. The only obligation is to maintain consistency between the class-model, .config files and database schema.

    Sincerely yours,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. huang
    huang avatar
    10 posts
    Member since:
    Jun 2009

    Posted 02 Jul 2009 Link to this post

    Hi Zoran,
    Thanks for your reply. 
    In your explanation, the persistent classes is also a "Code file". In other words, I still need to modify the classes and recompile .
    Is there any methods to do same job without compiling  code again ? 

    Thanks again
    Andre'
  4. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 02 Jul 2009 Link to this post

    Hi huang,

    It depends on what are you changing in the config file. If you change names of fields of persistent classes, or the identity field of a class etc.. there is no way but re-compiling to reflect those changes. If you change the server-name, database name, connectionId or some other configuration entries that are not related to the persistent classes model directly, you can to that during runtime with no need for re-compiling.

    If you give me a concrete scenario I could give you more specific answer about the OpenAccess workflow in such circumstances.

    Best wishes,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. huang
    huang avatar
    10 posts
    Member since:
    Jun 2009

    Posted 07 Jul 2009 Link to this post

    Hi Zoran,

    For example, There is a "club member" system, and I add  a new field "Member's Hobby" in this system. After I change the database schema dynamically, I expect that the server can recognize the new field and provide some kinds of methods to access the new field.
    Thanks for your patient!

    Sincerely,
    Andre'
  6. Answer
    Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 10 Jul 2009 Link to this post

    Hello huang,

    If the field is a class member, then the runtime will recognize it a a normal field, but only after recompilation.
    If you want to dynamically add fields during runtime and than use them without recompiling, but just changing the database schema, then I recommend you to check our generic data access and artificial fields API. With this approach you access the fields using TypeDescriptors and PropertDescriptors and manipulate with their values in a generic way. If you want to add fields and continue to work with them without recompiling your assembly, then you should use artificial fields.

    You can find more information about those features in the following blog post. You can also read our documentation articles on Generic Metadata Access and Artificial Fields.

    Greetings,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. huang
    huang avatar
    10 posts
    Member since:
    Jun 2009

    Posted 16 Jul 2009 Link to this post

    Hi Zoran:
    Thanks for your last reply. It helps me a lot find the way to achieve my goal. But I get another problem now. After I add the new schema into database and access it by metadata access method(setvalue and getvalue), I also need to modify record. But I can't find any sample to do that. Is there a method to select one record and  to update the artificial field? Doesn't the OQL and SQL provide "Update" and "Delete" action?

    Sincerely,
    andre'
  8. huang
    huang avatar
    10 posts
    Member since:
    Jun 2009

    Posted 20 Jul 2009 Link to this post

    Hi
    I think I need to describe my problem more clearly. I want to use query method  to retrieve a record
    (includeing the artificial fields),but it seems I can only get the original columns. Did I miss something
     in my operation as following?
    1.Use query to get records in DB
    2.set a GridView's datasource to the queryresult
    3.databind the Gridview 
    4.Find the result of missing the new columns


    Sincerely,
    andre'
  9. Answer
    Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 21 Jul 2009 Link to this post

    Hi huang,

    Yes, your question is a common one when using the artificial fields functionality. You should check our Generic Metadata Access and Artificial fields API example. You can find it in the quickstart solution distributed with the Telerik OpenAccess ORM product installation.
    The persistent class you plan to present in the grid should have the TypeDescriptorProvider attribute so the grid can use your custom type descriptor provider base on the PersistenMetadata provided by the IObjectScope. Consider the following example code:
    [TypeDescriptionProvider(typeof(MyTypeDescriptionProvider))] 
        [Telerik.OpenAccess.Persistent(IdentityField = "id")] 
        public class Person 
        { 
          ... 

    Here is the sample implementation of the custom TyoeDescriptorProvider:
    public class MyTypeDescriptionProvider : TypeDescriptionProvider 
        { 
            private IObjectScope scope; 
     
            private TypeDescriptionProvider GetMetaData() 
            { 
                scope = Database.Get("DBConnFirstSteps").GetObjectScope(); 
                return scope.PersistentMetaData; 
            } 
     
            public override object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args) 
            { 
                return GetMetaData().CreateInstance(provider, objectType, argTypes, args); 
            } 
            public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) 
            { 
                return GetMetaData().GetTypeDescriptor(objectType, instance); 
            } 
        } 

    That way, when the grid binds to a collection containing your persistent objects it will always use the Telerik OpenAccess ORM metadata model, which by itself contains all the persistent fields, including the artificial ones.

    Best wishes,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. huang
    huang avatar
    10 posts
    Member since:
    Jun 2009

    Posted 21 Jul 2009 Link to this post

    Hi Zoran,
    Thanks you very much! It seems that I miss the TypeDescriptorProvider attribute in the class.After I did this step,It worked well.
    In addition, Would you help me check the following SQL query string? I can use OQL query string to get the records. But  It doesn't work when I use SQL query string.
    ----------------------------------------------------------------------------------------------------------------
    string SQLquery="SELECT * FROM TEST WHERE key>?" ;
    var  SQLresult =scope.GetSqlQuery(SQLquery,typeof(Test),"integer key").Execute(3);
    gvtest.datasource=SQLresult;
    gvtest.databind();
     ----------------------------------------------------------------------------------------------------------------
    Also, Could I use query string like "Update ...." or "Delete ...." ?
    If it can't do that, would you please give me some hints to do the job?
    I learn Getvalue() and Setvalue() from your support doc. I can Read/Write(Add),but how to modify field's value In my query result.?

    Thanks In Advance
    Sincerely,
    andre'
  11. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 24 Jul 2009 Link to this post

    Hello huang,

    Is it possible that your sql table is named TESTS but not TEST? If this is not the case then your query should work out fine. If you would like to use SQL query to update or delete records than the best approach would be to create stored procedures and call them through the GetSqlQuery method. Additional information can be found here.

    Regards,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  12. huang
    huang avatar
    10 posts
    Member since:
    Jun 2009

    Posted 28 Jul 2009 Link to this post

    Hello Petar,

    I have checked my DB's table name. And it's right!. It worked well when I used the OQL string to query .
    After considering your recommendation for Db access, I had a new problem .
    If I use store procedure to update / delete schema, I need to write different store procedure for different Database.
    It 's a big problem In our developement. is there any other method to do the same job except Store Procedure?

    Sincerely,
    andre'
  13. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 29 Jul 2009 Link to this post

    Hi huang,
    depends on the stored procedure you want to create. If you would like to construct stored procedures for the Basic crud operations than Telerik OpenAccess ORM can do that for you automatically. You can find additional information here.
    If you would like to have some custom stored procedures involved, I am afraid that the only way will be to write them by hand.

    All the best,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top