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

Transparent persistance?

3 Answers 98 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ManniAT
Top achievements
Rank 2
ManniAT asked on 19 Dec 2008, 06:46 PM
Hi,

I'm new to OA and (missing some simple basic examples) I browsed around a bit in blogs and other things.

First of all -- the Tool is great.
Simply make a few clicks and have a table generated from a class.
I use SQL 2005 as database.
First thing I noticed -- I had to change all VARCHARS to NVARCHARS - I found no way to set this as default.
Anyhow - I could create a table with a few mousclicks.

Last not least - now I am at the same step as if I would have created the class via LINQ to SQL.
The pro till now --- LINQ to SQL requires a lot of "code changeing" and it works "reverse" so the class follows the DB.

Now with LINQ I get (with almos the same effort as with OA) a list of my records.
Further I act with this list - update my Fields anywhere in code and so on.
Absolutly no contact with LINQ to SQL at the moment.

When I decide to save my Changes I write db.SubmitChanges(); - done.

What means for me that (for an example) if I want to bind my data to a WPF form I add a "load data" button which makes a few lines of "LINQ to SQL" calls - retrive a list (Table) bind it to controls and done.
To store the values - another button which calls the "SubmitChanges()".
(I assume no adding / deleting).

--------
From what I learned with OA (Ralph's great blog http://object-relational-mapping.blogspot.com/2007/03/basic-crud-operations-part-22.html) I always have to encapsulate updates in a transaction.

So far I see this now - I have to mess around with OA not only at loading / storing - but also druing updates.
Did I missunderstand something, or is this like I think?


Sorry if I ask stupid questions - but I'm missing simple examples like the ones for LINQ where such things are covered in a very basic way. Your (much more featured) examples are to complex for me to find the "basic operations" in code.

CONCLUSION (questions):
a.) Is there a way to "default" the desinger to NVARCHAR with strings in SQL Server?
b.) Is there some simple example which does
----1,) Read a list of (simple) Objects from a table (no refs nothing)
----2.) Insert an object (not persisting at the moment)
----3.) Delete an object (not persisiting at the moment)
---4.) Change some values of an object (also not persisting)
---5.) Write back all the changes at a specific moment (Button Click or so)

Regards

Manfred

3 Answers, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 20 Dec 2008, 11:42 AM
Hi Manfred

         We are really pleased to see our customers happy. Because you are new to Tekerik OpenAccess ORM I would like to recommend you our knowledge-base: it contains exactly what you need to get started like basic CRUD operations sample, inheritance, forward and reverse mapping. Hopefully the KnowledgeBase will help you get more familiar with OpenAccess.

Regarding your question how to default map the CLR string type to NVARCHAR you can use the OpenAccess main menu entry in Visual Studio: OpenAccess->Configuration->Backend Configuration Settings.
There are eight sections in the dialog that will open and what is of interest to you is the "Type Mapping" section. There you can set how every CLR datatype maps to a database type.


 We are looking forward for your feedback that will help us improve OpenAccess ORM further.


Regards,
Zoran
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
ManniAT
Top achievements
Rank 2
answered on 20 Dec 2008, 01:49 PM
First of all - thank you for the fast and informative answers.

The KB articles you pointed to helped a lot.

BUT they showed what I had expected from looking around in blogs so far.
OR I am wrong - what's also possible.

The code I found was:

var result = from o in scope.Extent<Order>()     
             where o.Customer.Contains("John")     
             select o;     
    
scope.Transaction.Begin();     
Order firstJohnOrder = (Order)result.First();     
firstJohnOrder.Customer = "Sir John The First";     
scope.Transaction.Commit();     
    
 

It can be due to the compact example - what me irritates is the need for the "sourrounding transaction".
I LINQ I would retrive the data in almost the same way.
Then I simply work with the data - and at some specific point I call db.SubmitChanges() which finally writes back the data to the database.

So (I guess) scope.Transaction has almost the same functionality (some aspects of it) as "db" (DataContext) in LINQ.
Or in other words - compared to LINQ:
a.) Create a DataContext
b.) Retrieve Objects
c.) Work with these Objects (bind to controls, manipulate and so on)
d.) Call SubmitChanges Method of the DataContext
e.) Destroy the DataContext
I OA I would do:
a.) Create a context
b.) Retrieve Objects via that context
c.) Begin a transaction
d.) Work with the Objects
e.) Call Transaction.Commint
f.) Destroy the Context

Or in simple words:
In OA I have one extra call - that is to begin such a transaction.
Am I right?

Regards

Manfred
0
Zoran
Telerik team
answered on 20 Dec 2008, 03:29 PM
Hi Manfred

       We are glad our KB articles have helped you. For users like yourself preferring to work the LinqToSql way we should have mentioned the scope.Transaction.AutomaticBegin property. When set to true it makes the call of scope.Transaction.Begin() method avoidable. You can call scope.Transaction.Commit() to make changes to your database anytime.

  I will edit my KB article to include information on this feature. Thanks for the suggestion. 

Regards,
Zoran
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Getting Started
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Zoran
Telerik team
ManniAT
Top achievements
Rank 2
Share this question
or