How to dynamically select reverse mapping or forward mapping?

Thread is closed for posting
6 posts, 0 answers
  1. rent
    rent avatar
    36 posts
    Member since:
    May 2008

    Posted 09 Feb 2010 Link to this post

    Hello ALL!!!

    In my Win Forms project I want to make a selecting reverse mapping or forward mapping dynamically and in both situation I want select Database dynamically too.

    Any ideas or sample solutions?

    Thanks in advance.

  2. rent
    rent avatar
    36 posts
    Member since:
    May 2008

    Posted 10 Feb 2010 Link to this post

    So, Let's open a situation. I want to writes to DB values of this format:

        public class DataValue  
        {  
            private DateTime timestamp;  
            private int obj_parameter_id;  
            private double value;  
            public DateTime TIMESTAMP  
            {  
                get { return this.timestamp; }  
                set { this.timestamp = value; }  
            }  
            public int OBJ_PARAMETER_ID  
            {  
                get { return this.obj_parameter_id; }  
                set { this.obj_parameter_id = value; }  
            }  
            public double VALUE  
            {  
                get { return this.value; }  
                set { this.value = value; }  
            }  
        } 
    And I want to write this values with this conditions:

    1) If the user don't specify the DB then create DB and made table OBJ_PARMETER_VALUE with thus fields and writes data to this table;

    2) If the user specify the DB and user prepared own table for this then need mutching between user fields in table and structure given above;

    3) When in code made Transaction.Commit() output to user how many records was inserted/updated

    Thanks in advance

  3. rent
    rent avatar
    36 posts
    Member since:
    May 2008

    Posted 12 Feb 2010 Link to this post

    Anyone have this situation? Or why can help me? Please....
  4. Ady
    Admin
    Ady avatar
    589 posts

    Posted 12 Feb 2010 Link to this post

    Hi rent,

     Sorry for delayed reply. Yes you can easily achieve what you have specified. You can do the following
    • Enable the project (for OpenAccess) that has your model classes using the 'Enable Project' wizard.
    • Use the Forward mapping wizard to specify the mapping for the classes and it's fields - the table and column names etc.
    • At runtime you can check whether the specified database exists and whether it matches the mapping specified for your class model
    • If it does not you can use the 'SchemaHandler' API to migrate the database to what is required

     You can use the Database.Get overload to specify connection information at runtime (based on the database that the user specifies) and use the returned Database instance to obtain the SchemaHandler instance. You can find a similar example here.

    Do get back to us in case you need further assistance.

    Best wishes,
    Ady
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. rent
    rent avatar
    36 posts
    Member since:
    May 2008

    Posted 14 Feb 2010 Link to this post

    Thanks for your answer Ady. 

    But how to enable to user select Database type (MS SQL Server, Oracle, Firebird, etc) in runtime? 

  6. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 16 Feb 2010 Link to this post

    Hi rent,

    This information is part of the backend configuration node in the app.config file (backend="mssql"). You can use the Database.Get() method that requieres an xmlelement. You can create your own connection and backend configuration node and set the backend during runtime. Please have a look here:

    http://www.telerik.com/help/openaccess-orm/telerik.openaccess-telerik.openaccess.database-get(string,xmlelement).html

    All the best,
    Jan Blessenohl
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top