This is a migrated thread and some comments may be shown as answers.

How to dynamically select reverse mapping or forward mapping?

5 Answers 83 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
rent
Top achievements
Rank 1
rent asked on 10 Feb 2010, 05:55 AM

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.

5 Answers, 1 is accepted

Sort by
0
rent
Top achievements
Rank 1
answered on 10 Feb 2010, 07:03 PM

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

0
rent
Top achievements
Rank 1
answered on 12 Feb 2010, 09:13 AM
Anyone have this situation? Or why can help me? Please....
0
Ady
Telerik team
answered on 12 Feb 2010, 11:26 AM
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.
0
rent
Top achievements
Rank 1
answered on 14 Feb 2010, 05:04 PM

Thanks for your answer Ady. 

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

0
Jan Blessenohl
Telerik team
answered on 16 Feb 2010, 09:50 AM
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.
Tags
General Discussions
Asked by
rent
Top achievements
Rank 1
Answers by
rent
Top achievements
Rank 1
Ady
Telerik team
Jan Blessenohl
Telerik team
Share this question
or