public void SeekTestDynamic() { var sw1 = new Stopwatch(); var store = new SqlCeDataStore("test.sdf"); store.CreateOrUpdateStore(); // populate test data var fieldList = new List <FieldAttribute>(); fieldList.Add(new FieldAttribute() { FieldName = "ID", IsPrimaryKey = true, DataType = System.Data.DbType.Int32 }); fieldList.Add(new FieldAttribute() { FieldName = "SeekField", DataType = System.Data.DbType.Int64, AllowsNulls = false, SearchOrder = FieldSearchOrder.Ascending }); fieldList.Add(new FieldAttribute() { FieldName = "Data", DataType = System.Data.DbType.String, AllowsNulls = false }); var definition = new DynamicEntityDefinition("DynamicSeekItem", fieldList, KeyScheme.Identity); store.RegisterDynamicEntity(definition); for (int i = 0; i < 100; i++) { var de = new DynamicEntity("DynamicSeekItem"); de.Fields["SeekField"] = i * 10; de.Fields["Data"] = "Item " + (i * 10).ToString(); store.Insert(de); } // no delegate sw1.Reset(); sw1.Start(); var item = store.First("DynamicSeekItem", System.Data.SqlServerCe.DbSeekOptions.BeforeEqual, "SeekField", 11); sw1.Stop(); // item should have a value of 10 }
public void BasicDynamicCRUDTest() { var fieldList = new List <FieldAttribute>(); fieldList.Add(new FieldAttribute() { FieldName = "ID", IsPrimaryKey = true, DataType = System.Data.DbType.Int32 }); fieldList.Add(new FieldAttribute() { FieldName = "FirstName", DataType = System.Data.DbType.String }); fieldList.Add(new FieldAttribute() { FieldName = "LastName", DataType = System.Data.DbType.String, AllowsNulls = false }); var definition = new DynamicEntityDefinition("People", fieldList, KeyScheme.Identity); var store = new SqlCeDataStore(Path.Combine(TestContext.TestDir, "test.sdf")); store.CreateStore(); Assert.IsFalse(store.TableExists(definition.EntityName)); store.RegisterDynamicEntity(definition); Assert.IsTrue(store.TableExists(definition.EntityName)); var entity = new DynamicEntity("People"); entity.Fields["FirstName"] = "John"; entity.Fields["LastName"] = "Doe"; store.Insert(entity); entity = new DynamicEntity("People"); entity.Fields["FirstName"] = "Jim"; entity.Fields["LastName"] = "Smith"; store.Insert(entity); entity = new DynamicEntity("People"); entity.Fields["FirstName"] = "Sam"; entity.Fields["LastName"] = "Adams"; store.Insert(entity); var items = store.Select("People"); DumpData(items); store.Delete("People", items.First().Fields["ID"]); items = store.Select("People"); DumpData(items); store.Delete("People", "LastName", "Smith"); items = store.Select("People"); DumpData(items); var person = items.First(); person.Fields["FirstName"] = "Joe"; person.Fields["LastName"] = "Satriani"; store.Update(person); items = store.Select("People"); DumpData(items); // now let's change the structure and see what happens fieldList.Add(new FieldAttribute() { FieldName = "Middle_Name", DataType = System.Data.DbType.Double, AllowsNulls = true // this has to be true to add a column }); var newDefinition = new DynamicEntityDefinition("People", fieldList, KeyScheme.Identity); store.RegisterDynamicEntity(newDefinition, true); items = store.Select("People"); }