Database usage

Jul 14, 2009 at 3:59 AM

Sergey,

Pretty cool project! Are you planning to create a LINQ access method for it (LINQ-to-SBDB)?

Ken

Coordinator
Jul 18, 2009 at 12:42 AM

Parts of Linq to objects already work with it.  You can do any select statments against it, and it will work.  For example here is my Select test (I checked it in):

private void SelectConditionTest()

        {

            Database.DeleteDatabase("test");

            Database db = Database.CreateDatabase("test");

            db.CreateTable<Person>();

 

            Person person1 = new Person() { FirstName = "John ", LastName = "Doe ", Salary = 1, BirthDate = new DateTime(1900, 1, 1) };

            Person person2 = new Person() { FirstName = "John ", LastName = "Doe ", Salary = 2, BirthDate = new DateTime(1900, 1, 1) };

            Person person3 = new Person() { FirstName = "John ", LastName = "Doe ", Salary = 3, BirthDate = new DateTime(1900, 1, 1) };

 

            db.Table<Person>().Add(person1);

            db.Table<Person>().Add(person2);

            db.Table<Person>().Add(person3);

 

            var query = (from onePerson in db.Table<Person>()

                         where onePerson.Salary == 2

                         select onePerson);

 

 

 

            if (query.Count() == 1)

            {

                this.LinqSelectTestLabel.Foreground = new SolidColorBrush(Colors.Green);

            }

            else

            {

                this.LinqSelectTestLabel.Foreground = new SolidColorBrush(Colors.Red);

            }

 

        }

<!--EndFragment-->

To handle deletes I wrote RemoveRange that takes a condition.  I think if a table is bound to a grid, and grid triggers a delete, this will also work. 

Is there a specific scenario I need to think about?  I must be missing something.

 

Sergey.

Jul 22, 2009 at 6:10 PM

Nice work, Sergey. I like the idea.

I have recently developed a custom tool that generates entities and partial class from .dbml. So if you are used to working with LINQ to SQL classes you could use Visual Studio to create a .dbml file and create code for Silverlight Database project (this project).

Using the generated code would look like:

// Current silverdb version, tables are attached at run time
db.Table().Add(person1);

// More like LINQ-to-SQL version, tables are known at design time
db.Persons.Add(person1);

// Also the Person class would be generated and available at design time

If you are intereseted we can continue the discussion...

-papnkukn

Coordinator
Jul 23, 2009 at 12:38 AM

Yes, I can see that this can be useful.  It will probably require writing a custom generator that would create a specific instance of a database with pre-typed tables.  I am kind of way too busy for the next 5 days, then I will have some more time.  I still have a few features I would like to implement as well.  Feel free to post what exactly you would like to see, then I can see if it is possible to write a generator to go along with db.