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

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

12 Answers 171 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.
huang
Top achievements
Rank 1
huang asked on 25 Jun 2009, 03:56 AM
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'

12 Answers, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 30 Jun 2009, 05:26 PM
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.
0
huang
Top achievements
Rank 1
answered on 02 Jul 2009, 08:52 AM
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'
0
Zoran
Telerik team
answered on 02 Jul 2009, 12:08 PM
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.
0
huang
Top achievements
Rank 1
answered on 07 Jul 2009, 08:08 AM
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'
0
Accepted
Zoran
Telerik team
answered on 10 Jul 2009, 12:12 PM
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.
0
huang
Top achievements
Rank 1
answered on 16 Jul 2009, 11:59 AM
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'
0
huang
Top achievements
Rank 1
answered on 20 Jul 2009, 11:06 AM
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'
0
Accepted
Zoran
Telerik team
answered on 21 Jul 2009, 03:07 PM
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.
0
huang
Top achievements
Rank 1
answered on 22 Jul 2009, 03:51 AM
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'
0
PetarP
Telerik team
answered on 24 Jul 2009, 07:08 AM
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.
0
huang
Top achievements
Rank 1
answered on 28 Jul 2009, 09:04 AM
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'
0
PetarP
Telerik team
answered on 29 Jul 2009, 02:00 PM
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.
Tags
General Discussions
Asked by
huang
Top achievements
Rank 1
Answers by
Zoran
Telerik team
huang
Top achievements
Rank 1
PetarP
Telerik team
Share this question
or