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

General Data Storag Questions

4 Answers 26 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.
ManniAT
Top achievements
Rank 2
ManniAT asked on 28 Feb 2014, 11:53 AM
Hi,

I just recognized your "Data Storage" for WP / W8.
And I found no forum for this product so I decided to write here.

Currently I run a WP project using SQLCompact with Linq2SQL.
My approach is DB first - so I use a tool to generate my database, fill in some "static" / initial data and further let the tool create a DBContext.

My WP application also has a counterpart running on WPF using SQLSerer (express).
Since the Linq2SQL syntax an behavior is (almost) the same at both systems I can share most of my code between both applications.

The problem here is Windows 8, since there is no (MS native) database support.

So it looks as if "Data Storage" could enable me to build for WP and Windows 8 using the same DB.
Now I have several questions regarding to "Data Storage" and Linq2SQL compatibility - or in other words - how much work would it be to migrate and what do I loose when I migrate.

First question - is "Data Storage" also available for WPF (Windows Desktop apps)?

Second question - is there any support for "data first" or do I have to use "code first"?
Third question - related to second - is there "tooling" (like SQLMetal or so) for this? (Some kind of "Generate Context from DB").
Something like DbLinq or so.

The rest is about "coding".
I'll use your car example from your documentation for these questions.

I changed the design a little bit - so the car has no "AutoID" instead is uses a combined Key.

C
public class CarOwners
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public long OwnerID { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public bool Alive { get; set; }
    public DateTime DateBorn { get; set; }
}
 
public class Cars
{
    [Key]
    public long OwnerFK { get; set; }
   [Key]
    public short CarNumber{ get; set; }
    public string Model { get; set; }
    public DateTime YearOfModel { get; set; }
    public string RegistrationNumber { get; set; }  
    public long CategoryID{ get; set; }
}
 
public class Categories
{
    [Key]
    public long CategoryID { get; set; }
    public string CategoryName { get; set; }
}

Using these classes an can (with Linq2SQL) create the following code.

DBContext DC=new....;
 
CarOwners owNer=(from A in DC.CarOwners where A.Name=="Joe" select A).FirstOrDefault();
//null check...
 
Categories sportsCarCategory=(from A in DC.Categories where A.CategoryName="SportsCar" select A).FirstOrDefault();
int numberOfCars=(from A in owNer.Cars select A).Count();
 
Cars newCar=new Cars() { Model="aaa", ... Category=sportsCarCategory, CarNumber=numberOfCars+1 };
owNer.Cars.Add(newCar);
DC.SubmitChanges();

"The magic" behind is that the DataContext automtically does the needed things like (in this case) select the Cars for the owner (when needes / accessed).
It sets the OwnderFK for the car when I add the new car to the owNer.Cars collection. The same for the Category. It generates the insert statement....

Would this also work with "Data Storage"?
And one step further...

DBContext DC=new....;
 
CarOwners owNer=new CarOwners() {......}
 
Categories sportsCarCategory=(from A in DC.Categories where A.CategoryName="SportsCar" select A).FirstOrDefault();
//now (just for fun) use the CategoryID
Cars newCar=new Cars() { Model="aaa", ... CategoryID=sportsCarCategory.CategoryID, CarNumber=1 };
 
owNer.Cars.Add(newCar);
DC.CarOwners.InsertOnSubmit(owNer);
DC.SubmitChanges();


Here first the CarOwner is inserted - next the (auto generated) OwnerID is retrieved from the DB and assing to OwnerFK in the new car...

Since the product (Data Storage) is new the documentation is a bit "poor".
So I have to ask some further questions.
Assume I have a service which can retrive car information.
But (lets say) the service gives me an "age" for the car and not the YearOfModel.
With Linq2SQL I solve this by adding an extra property Age which (in the setter) assings the correct YearOfModel.
This property (Age) is not persisted in the database.
So when I load a car from the DB this property is not set (or I implement the partial OnYearOfModelChanged or OnLoaded or I do some magic in the get accessor).

The question - is it possible to "enhance" a class with properties not persisted in the DB and are the "helper methods" like "OnLoaded"?
Especially OnLoaded is a thing I use a lot in my code.


Manfred





4 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 04 Mar 2014, 12:30 PM
Hi Manfred,

Here are the quick answers to your questions:

1. Data Storage for WPF: This component is only available for our mobile solutions. We do have an ORM solution for desktop: OpenAccess and it works with SQLite. For more information I suggest you write in the corresponding product's forums.

2. There is no "data first" support. You will have to use the "code first" support.

3. Could you please elaborate a bit further on the "tooling" question?  My simple answer to your question would be that we built on-top of SQLite so any tools that exist for SQLite are applicable in the Data Storage scenario as well.

4. We do not support multiple primary keys and the scenario described above will not work with Data Storage.

5. The documentation does not mention the OnLoaded event because it is not present. You can simply implement the corresponding OnLoaded method on your business objects and call it as soon as your retrieve the objects from the database. 

6. Any properties that are public and can be read and written are persisted in the database.

I hope my answers are helpful.

Let us know should you have additional questions.

Regards,
Deyan
Telerik
If you want to get updates on new releases, tips and tricks and sneak peek previews directly from the developers working on the UI for Windows Phone, subscribe to the blog feed now.
0
ManniAT
Top achievements
Rank 2
answered on 06 Mar 2014, 10:36 AM
Hi Deyan,

thank you for the answers.

Just to ensure I understood everything correct let me check this.

1.) I know you have OpenAccess - but I guess this doesn't really help to share data access code with my mobile apps.
2 + 3.) Since you do not support "data first" this eliminates the questions about "tooling" which would only be needed in data first (generate code from data like SQLMetal or so)

4.) I was asking for "comined keys" (more than one column included in the primary key)
But I guess from your answer that you only support "One Column primary keys" - am I right?

6.) This means I can't extend my class with "code only properties" since everything public is written to DB - which would fail  in this case because there are no columns for these properties.
Am I right?

Yes I have additional questions - or better I miss answers to the code snippets.
What about the "magic" like adding a car to the owners "Cars collection" results in an insert for the car or at least in changing the foreign key (owner change)??

My conclusion - what you provide is a very simple Linq to SQLite Provider without extended functionality like in other "wrappers" (for an example "LinqConnect", am I right?

What are the benefits over (just to name one popular) DbLinq (which even supports data first AFAIK with DBMetal)?

Thanks 
Manfred
0
Accepted
Deyan
Telerik team
answered on 06 Mar 2014, 12:07 PM
Hi Manfred,

Thanks for writing back.

I'll start from the end of your last answer :)

Yes, we are basically providing a wrapper over the SQLite engine for Windows Phone/Windows 8. We build on top to deliver ORM functionalities (you don't need to create columns for your tables, they are automatically created based on the objects you are storing), indexing, async support, LINQ2SQL, etc.

We wanted to create a very thing and lightweight component without the complications of a desktop oriented solution. The mobile world implies it more or less. We are of course listening to our customers' feedback and if there is strong demand for given feature we will certainly implement it.

Otherwise:

4) Yes, there is support for one-column primary keys only.
6) Each public property that has a getter and a setter will be automatically stored in the database without you having to create or delete new columns. That's the ORM part of our Data Storage component.

The major benefit of our Data Storage component is that you are entitled to 24 hour support. This is a commercial project which we are actively developing.

As far as I can tell, DBLinq is not officially supported on Windows Phone and any issues that you might encounter will not be easily fixable.

You should simply consider which scenarios are the most important for you and having the feature sets of both components - decide which one to use.

Regards,
Deyan
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

0
ManniAT
Top achievements
Rank 2
answered on 06 Mar 2014, 12:40 PM
Hi Deyan,

thank you for your ultra fast answer.

I agree with "24 hour support" and other things you wrote.

Unfortunaltely I just have to say "it doesn't fit my needs" for a replacement to Linq2Sql (SQL Mobile).
Not your (teleriks) fault - it's just a matter of the wrong expextations when I read "Linq database wrapper".

There are of course needs for a solution like you provide.


And to close this - there have been three reasons to find out what is possible.

"LinqConnect" (also commercial with support) would add extra cost while I own your product suite.
My experience with telerik - great support, high quality products - and most products are "platform independent" (as far as possible).
--this means for me - doing one thing in SL can be done the same way in WPF...
--I thought I read somewhere that "Data Storage" also works with Windows Store apps, so....
Last not least the experience that if you (telerik) offer new products there is (in most cases) much more possible than expected.
--So I thought - ok, it's not in the documentation ATM, but if they say....

Anyhow it's good to know the capabilities of this product - maybe I need it sometimes...

Regards
Manfred
Tags
General Discussions
Asked by
ManniAT
Top achievements
Rank 2
Answers by
Deyan
Telerik team
ManniAT
Top achievements
Rank 2
Share this question
or