Windows phone 7 database tutorial

Nov 27, 2010 at 7:51 AM

Hello,

I need to make a database for windows phone 7. I know it is not a big deal, but I do not know how to begin.

Could please tell me where could I find tutorial for 'very' beginners?

Thanks in advance.

Coordinator
Nov 27, 2010 at 12:12 PM

Sample test project included with source code should cover all basic scenarios for you, such as create database, add tables, add data and retrieve data. Please let me know if you have some additional questions.

Thanks.

 Sergey

Nov 29, 2010 at 6:48 AM
Dear Mr. Sergey Barskiy

I would like to know how to:
  • create a primary key of the table
  • join to tables with their primary keys (inner and outer key)
Thank you in advance.
Hristina Bosilkovska



From: [email removed]
To: [email removed]
Date: Sat, 27 Nov 2010 05:12:30 -0800
Subject: Re: Windows phone 7 database tutorial [WinPhone7DB:236213]

From: SergeyBarskiy
Sample test project included with source code should cover all basic scenarios for you, such as create database, add tables, add data and retrieve data. Please let me know if you have some additional questions.
Thanks.
Sergey
Read the full discussion online.
To add a post to this discussion, reply to this email (WinPhone7DB@discussions.codeplex.com@discussions.codeplex.com)
To start a new discussion for this project, email WinPhone7DB@discussions.codeplex.com@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com
Coordinator
Nov 29, 2010 at 11:07 AM

There is currently no support for indexes.  You PK column is just like any other field in the table - simply a property in your class you are storing.  Joining tables is really like any other Linq statement

from cl 1 in db.Tables<Class1>()

join c2 in db.Tables<Class2>() on c2.C1 eq c1.C1

select new {C1=c1.C1, C@= c2.C2}

 

Something like this anyway.

Dec 3, 2010 at 10:55 PM

Hi!

I have just noticed that the database is deleted ever time I start the application and is created a new one. I need the data from the previous time I have used the application. Please tell me how could I manage that.

I have written this piece of code:

 if (SilverlightPhoneDatabase.Database.DoesDatabaseExists("myDatabase"))

{                           MessageBox.Show("OPEN");                db = SilverlightPhoneDatabase.Database.OpenDatabase("myDatabase");            }    

       else            {                MessageBox.Show("Create");                db = SilverlightPhoneDatabase.Database.CreateDatabase("myDatabase");              

            db.CreateTable<Guest>();          

     db.Table<Guest>().Save();        

       db.CreateTable<Table>();          

     db.Table<Table>().Save();            

   db.CreateTable<ToDo>();            

   db.Table<ToDo>().Save();            

                           }

According to the message boxes it never opens the databes, it just creates the database every time.

Where could I find the database 'myDatabase'?

Your answer is really appreciated.

Thanks in advance.

Hristina

Dec 4, 2010 at 12:36 AM

I have resolved the problem.

I just needed to call the .Save() method.

else            {                MessageBox.Show("Create");                db = SilverlightPhoneDatabase.Database.CreateDatabase("myDatabase");              

            db.CreateTable<Guest>();          

     db.Table<Guest>().Save();        

       db.CreateTable<Table>();          

     db.Table<Table>().Save();            

   db.CreateTable<ToDo>();            

   db.Table<ToDo>().Save();          

db.Save(); 

                           }

 

 

Coordinator
Dec 4, 2010 at 1:16 PM

Usually you can just call db.Save() - it saves all the tables as part of it.

 

Sergey

Dec 9, 2010 at 6:09 PM

Hi there,

Being new to LINQ databases, would you please post a code snippet showing how to get data from a table based on some conditions and then put the changed data back in the table?

Thanks in advance,

docorrin

Coordinator
Dec 10, 2010 at 11:17 PM

Hi there.

Please take a look at the unit test project included with download.  It well demostrates all key APIs.  Please let me know if this is not sufficient and let me know what you are trying to achive.

Thanks.

Sergey

Dec 11, 2010 at 5:29 PM

Hi there,

Thanks for your reply. I wish to extract an element in the database table based on a condition. I am trying to do something like this:

                    db.Table<Person>().Select<Person, PersonReturn>((Person) => { return (Person.FirstName = "John"); });

but get the error

Error 1 Cannot convert lambda expression to delegate type 'System.Func<Person,int,PersonReturn>' because some of the return types in the block are not implicitly convertible to the delegate return type

Error 2 Cannot implicitly convert type 'string' to 'PersonReturn'

Also do you know of a good online reference which covers LINQ database usage?

Thanks in advance,

docorrin

 

 

Dec 11, 2010 at 6:06 PM

Hi again,

Actually what I wish to do is to extract this single record to a list.

Thanks for your help,

docorrin

Dec 11, 2010 at 6:54 PM

Hello I am interested in this program, how can I get on teh list to be allowed to run the project? Thanks Jon

Dec 12, 2010 at 2:52 AM

It is available on this link: http://silverdb.codeplex.com/

docorrin

Dec 12, 2010 at 2:31 PM

I write query this way:

 var queryTable = (from theTableEntries in MainPage.db.Table<MyClass>()  

                               select theTableEntries );                

List<MyClass> theTableEntriesList = queryTable.ToList<MyClass>();

 

 for (int j = 0; j < theTableEntriesList .Count; j++)                    {  

 singleTableEntry= theTableEntriesList .ElementAt<MyClass>(j);

}

 

OR you can write the query this way (in order to use conditions or where):

var queryTable = (from theTableEntries in MainPage.db.Table<MyClass>()  

where theTableEntries.name == "myName";

                               select theTableEntries );           

 

Coordinator
Dec 13, 2010 at 11:51 PM

@dcorrin

I think you are trying to select a person with a specific name.

var john =  db.Table<Person>().First(onePerson => onePerson.Name == "John");

Something like this.  Also, example above works as well.  Also, here is a link to a 2 page Linq guide: http://aspnetresources.com/downloads/linq_standard_query_operators.pdf

Thanks.

Sergey

May 11, 2011 at 10:57 AM

I am using this extensively in my WP7 apps on the MarketPlace. My wishlist for this would be

- Table name along with entity to allow creation of 2 tables using same schema
- backup and restore functionality of database
- allow schema additions (not deletion) in table even after records with old schema exist
- async call back functions when saving/deleting/updating data
- inherited support for LINQ - have to build a wrapper over it to get that support currently.
- support to send data through WCF / WebService calls

Guess, these will make it one of the best

 

Coordinator
May 11, 2011 at 11:06 AM

Thanks for the feedback.  When you say LINQ support is needed, what do you mean?  It should be there - you can look at the unit test project, I have some samples there already.  I will have to add these items to the to-do list for the project and prioritize them.  Did you list them in priority order?

May 11, 2011 at 11:41 AM

Thanks for the reply.

By LINQ support, I meant retrieval of records using predicate instead of retrieving all records and then applying a filter on them.

The wish list is in the order of priority.

Coordinator
May 11, 2011 at 11:44 AM

You mean reading them into memory before filter?