public void EntityPersisterWithInstanceTest() { using (var per = new EntityPersister <Products>("sqlite")) { Assert.IsNotNull(per); } }
public void EntityPersisterTest() { using (var per = new EntityPersister <Products>()) { Assert.IsNotNull(per); } }
public void GetEntityTypeTest() { using (var per = new EntityPersister <Products>(instanceName)) { Assert.AreEqual(typeof(Products), per.GetEntityType()); } }
public void QueryFirstTest() { using (var per = new EntityPersister <Products>(instanceName)) { var p = per.Query().FirstOrDefault(); Assert.IsNotNull(p); } }
public void CloneTest() { using (var per = new EntityPersister <Products>(instanceName)) { var product = per.Query().FirstOrDefault(); var newProduct = product.Clone(); } }
public void QueryForConditionTest() { using (var per = new EntityPersister <Products>(instanceName)) { foreach (var p in per.Query("productname <> '测试'", "productname desc")) { Console.WriteLine(p.ProductName); } } }
public void QueryTest() { using (var per = new EntityPersister <Products>(instanceName)) { foreach (var p in per.Query(s => true)) { Console.WriteLine(p.ProductName); } } }
public void QueryToDataTableTest() { using (var per = new EntityPersister <Products>(instanceName)) { foreach (DataRow row in per.Query("productid <> 0", null, null).Cast <IEntity>().ToDataTable().Rows) { Console.WriteLine(row.ItemArray.Length); } } }
public void CreateWithManualIdTest() { using (var per = new EntityPersister <Customers>(instanceName)) { var customer = new Customers { CustomerID = Guid.NewGuid().ToString(), CompanyName = "fireasy" }; per.Create(customer); } }
public void QueryForAnonymousTest1() { using (var per = new EntityPersister <Orders>(instanceName)) { foreach (var p in per.Query(s => true).Select(s => new { Orderdate = s.OrderDate, Country = s.Customers.Country })) { Console.WriteLine(p.Country); } } }
public void QueryForAnonymousTest() { using (var per = new EntityPersister <Products>(instanceName)) { foreach (var p in per.Query(s => true).OrderBy(s => s.ProductName).Select(s => new { Productname = s.ProductName })) { Console.WriteLine(p.Productname); } } }
public void QueryForMutilOrderTest() { using (var per = new EntityPersister <Products>(instanceName)) { foreach (var p in per.Query(s => true).OrderBy(s => new { Productid = s.ProductID, Productname = s.ProductName })) { Console.WriteLine(p.ProductName); } } }
public void QueryForWhereTest() { using (var per = new EntityPersister <Products>(instanceName)) { foreach (var p in per.Query(s => true).Where(s => (string)s.ProductName == "11")) { Console.WriteLine(p.ProductName); } } }
public void QuerySerializeTest() { using (var per = new EntityPersister <Products>(instanceName)) { //TypeDescriptor.RemoveProvider(new EntityTypeDescriptionProvider(), typeof(EntityObject)); var p = per.Query().FirstOrDefault(); var json = new JsonSerializer(); Console.WriteLine(json.Serialize(p)); } }
public void CreateTest() { using (var per = new EntityPersister <Categories>(instanceName)) { var product = new Categories { CategoryID = 1, CategoryName = "dd", Description = "aa" }; per.Create(product); } }
public void QueryForConditionParameterTest() { using (var per = new EntityPersister <Products>(instanceName)) { var parameters = new ParameterCollection(); parameters.Add("name", "测试"); foreach (var p in per.Query("productname = @name", string.Empty, null, parameters)) { Console.WriteLine(p.ProductName); } } }
public void QueryForSqlTest() { using (var per = new EntityPersister <Products>(instanceName)) { foreach (object p in per.Query((SqlCommand)"select productname from products")) { var f = p.GetType().GetProperty("productname"); var v = f.GetValue(p, null); Console.WriteLine(v); } } }
public void QueryJoinTest() { using (var per = new EntityPersister <Customers>(instanceName)) { var list = from c in per.Query() join o in per.Query <Orders>().DefaultIfEmpty() on c.CustomerID equals o.CustomerID select new { Contactname = c.ContactName, Orderid = o.OrderID }; foreach (var s in list) { Console.WriteLine(s.Orderid); } } }
public void QueryForPagerTest() { using (var per = new EntityPersister <Products>(instanceName)) { var pager = new DataPager(2) { CurrentPageIndex = 1 }; foreach (var p in per.Query(s => true).Segment(pager)) { Console.WriteLine(p.ProductName); } } }
public void CreateForIdentityTest() { using (var per = new EntityPersister <Identitys>(instanceName)) { //Id1 为自增长类型 //Id2 使用生成器生成 //Id3 Guid var identity = new Identitys(); per.Create(identity); Console.WriteLine(identity.Id1); Console.WriteLine(identity.Id2); Console.WriteLine(identity.Id3); } }
public void BatchCreateTest() { using (var scope = new EntityTransactionScope()) using (var per = new EntityPersister <Categories>(instanceName)) { var products = new List <Categories>(); for (var i = 0; i < 1000; i++) { products.Add(new Categories { CategoryID = i + 1, CategoryName = "测试" + i, Description = "aa" }); } per.BatchCreate(products); scope.Complete(); } }
public SessionFactoryImpl(Configuration cfg, Settings settings) { this.settings = settings; //settings.CacheProvider.Start(null); #region Persisters entityPersisters = new Dictionary<string, IEntityPersister>(); foreach (ClassMetadata model in cfg.ClassMappings) { //string cacheRegion = model.EntityName; //ICacheConcurrencyStrategy cache; //if (!caches.TryGetValue(cacheRegion, out cache)) //{ // cache =CacheFactory.CreateCache(model.CacheConcurrencyStrategy, cacheRegion, model.IsMutable, settings, properties); // if (cache != null) // { // caches.Add(cacheRegion, cache); // } //} IEntityPersister cp = new EntityPersister(model, this); // PersisterFactory.CreateClassPersister(model, cache, this, mapping); entityPersisters[model.EntityName] = cp; } #endregion #region Serialization info name = settings.SessionFactoryName; uuid = Guid.NewGuid().ToString("N"); SessionFactoryObjectFactory.AddInstance(uuid, name, this); #endregion currentSessionContext = BuildCurrentSessionContext(); }
public SessionFactoryImpl(Configuration cfg, Settings settings) { this.settings = settings; //settings.CacheProvider.Start(null); #region Persisters entityPersisters = new Dictionary <string, IEntityPersister>(); foreach (ClassMetadata model in cfg.ClassMappings) { //string cacheRegion = model.EntityName; //ICacheConcurrencyStrategy cache; //if (!caches.TryGetValue(cacheRegion, out cache)) //{ // cache =CacheFactory.CreateCache(model.CacheConcurrencyStrategy, cacheRegion, model.IsMutable, settings, properties); // if (cache != null) // { // caches.Add(cacheRegion, cache); // } //} IEntityPersister cp = new EntityPersister(model, this); // PersisterFactory.CreateClassPersister(model, cache, this, mapping); entityPersisters[model.EntityName] = cp; } #endregion #region Serialization info name = settings.SessionFactoryName; uuid = Guid.NewGuid().ToString("N"); SessionFactoryObjectFactory.AddInstance(uuid, name, this); #endregion currentSessionContext = BuildCurrentSessionContext(); }
internal object GetIdentifier(object entity) { return(HasCompositeKey ? GetIdentifierValues(entity) : EntityPersister.GetIdentifier(entity)); }
protected virtual void DoSaveData(EntityPersister persister, IEntity entity) { persister.Save(entity); }