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
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; } |
} |
} |
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
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.
Thanks for your answer Ady.
But how to enable to user select Database type (MS SQL Server, Oracle, Firebird, etc) in runtime?
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.