Home   Notes   Contact Me

LINQ

Local

External


SQL Server Compact Edition Info

Creating a .dbml file

Visual Studio (at this time) does not allow graphical tool creation of LINQ dbml files, so you have to create them manually.

# Using a command prompt from Visual Studio Tools (look under Start and then Visual Studio) # goto the directory with the .sdf file (the SQL Server Compact Edition database file) # for this example the database file is named myDB.sdf SqlMetal /dbml:./LinqToMyDB.dbml ./myDB.sdf

Using the .dbml file

pubic UsingClass { private myDB dbContext; public UsingClass() { dbContext = new myDB(Properties.Settings.Default.myDBConnectionString); var results = from item in db.TABLENAME select item; foreach(var result in results) { System.Console.writeln(result); } } }

Possibly useful tool (SqlMetal gui): http://sourceforge.net/projects/sqlmetalbuilder/

Reference: http://castalian.wordpress.com/2008/01/12/linq-to-sql-compact-edition-ce/


UPDATE

var findItem5 = (from item in table where item.id == 5 select item).Single(); // don't change: findItem5.id // change the rest findItem5.Name = "new name"; findItem5.Value = 33; db.SubmitChanges();
int[] table = { 0, 9, 1, 8, 2, 7, 3, 4, 6, 5 }; var find5to7 = from n in table where n >= 5 && n <= 7 select n; foreach (var result in find5up) { Console.WriteLine("val: " + result); }

WHERE

int[] table = { 0, 9, 1, 8, 2, 7, 3, 4, 6, 5 }; var find5up = from n in table where n >= 5 select n; foreach (var result in find5up) { Console.WriteLine("val: " + result); }
int[] table = { 0, 9, 1, 8, 2, 7, 3, 4, 6, 5 }; var find5to7 = from n in table where n >= 5 && n <= 7 select n; foreach (var result in find5up) { Console.WriteLine("val: " + result); }