private void RunAssert(CoreObject co) { if (co._CustomProperties["MyBoolProp"] is bool) { Console.WriteLine(" MyBoolProp is bool :)"); } else { Console.WriteLine(" MyBoolProp is NOT bool"); } if (co._CustomProperties["MyDateTime"] is DateTime) { Console.WriteLine(" MyDateTime is dateTime :)"); } else { Console.WriteLine(" MyDateTime is NOT datetime"); } if (co._CustomProperties["Settings"] is CustomerSettings) { Console.WriteLine(" Settings is CustomerSettings :)"); } else { Console.WriteLine(" Settings is NOT CustomerSettings"); } if (co._CustomProperties["MyList"] is IList && co._CustomProperties["MyList"].GetType().IsGenericType) { Console.WriteLine(" MyList is generic List :)"); } else { Console.WriteLine(" MyList is NOT generic List"); } if (co is Customer) { Console.WriteLine(" is Customer :)"); Customer cust = (Customer)co; if (cust.ContactDetails?.ContactItemList?[0] is AlfaOnline) { Console.WriteLine(" ContactItem is AlfaOnline :)"); } else { Console.WriteLine(" ContactItem is NOT AlfaOnline"); } } else { Console.WriteLine(" is NOT customer"); } }
private void RunInsertAndRead() { Customer c = new Customer() { Username = "******", DeletedTime = DateTime.MaxValue, MyTimeSpan = new TimeSpan(1, 30, 0) }; c.ContactDetails = new ContactDetails(); c.ContactDetails.ContactItemList = new List <ContactItem>(); c.ContactDetails.ContactItemList.Add(new AlfaOnline("a", "b", "C")); c._SetCustomProperty("MyBoolProp", true); c._SetCustomProperty("MyDateTime", DateTime.Now); c._SetCustomProperty("Settings", new CustomerSettings() { CustomerConnect_NotifCancelled = true, NotifFinished = true }); c._SetCustomProperty("MyList", new List <uint> { 1, 2, 3, 4 }); CoreObject co = c; long id; using (IDbConnection db = _dbFactory.Open()) { var typedApi = db.CreateTypedApi(co.GetType()); id = typedApi.Insert(co, selectIdentity: true); Console.WriteLine($" Insert - Untyped: {id}"); string tableName = co.GetType().GetModelMetadata().ModelName; List <Dictionary <string, object> > results = db.Select <Dictionary <string, object> >($"SELECT * FROM {tableName} where id={id}"); List <CoreObject> coreObjects = results.Map(x => (CoreObject)x.FromObjectDictionary(co.GetType())); Console.WriteLine($" Read - Untyped + FromObjectDict: {id}"); RunAssert(coreObjects[0]); Console.WriteLine($" Read - Typed: {id}"); coreObjects = db.Select <CoreObject>($"SELECT * FROM {tableName} where id={id}"); Customer cDes = db.SingleById <Customer>(id); RunAssert(cDes); Console.WriteLine(); id = db.Insert <Customer>(c, selectIdentity: true); Console.WriteLine($" Insert - Typed: {id}"); Console.WriteLine($" Read - Untyped + FromObjectDict: {id}"); results = db.Select <Dictionary <string, object> >($"SELECT * FROM {tableName} where id={id}"); coreObjects = results.Map(x => (CoreObject)x.FromObjectDictionary(co.GetType())); RunAssert(coreObjects[0]); Console.WriteLine($" Read - Typed: {id}"); cDes = db.SingleById <Customer>(id); RunAssert(cDes); }; }
public override bool Equals(object obj) { if (obj == null || !obj.GetType().IsSubclassOf(typeof(CoreObject))) { return(false); } CoreObject co = (CoreObject)obj; if (this.Id == co.Id) // borde kolla type också? Obj kan ju ersättas, samma id men annan typ? { return(true); } else { return(false); } }