This question is locked. New answers and comments are not allowed.
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
Using these classes an can (with Linq2SQL) create the following code.
"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...
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
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