Esempio n. 1
0
        static void Setter(IDictionary <int, Dictionary <string, object> > storage, CustomSetterGetterBase instance, string property, object value)
        {
            if (!storage.ContainsKey(instance.Id))
            {
                storage.Add(instance.Id, new Dictionary <string, object>());
            }

            storage[instance.Id][property] = value;
        }
Esempio n. 2
0
        public void TestDynamicColumnStoreExpressions([IncludeDataSources(true, TestProvName.AllSQLite)] string context)
        {
            var storage = new Dictionary <int, Dictionary <string, object> >();

            var ms      = new MappingSchema();
            var builder = ms.GetFluentMappingBuilder();

            builder.Entity <CustomSetterGetterBase>()
            .DynamicPropertyAccessors(
                (instance, property, defaultValue) => Getter(storage, instance, property, defaultValue),
                (instance, property, value) => Setter(storage, instance, property, value))
            .HasColumn(e => e.Id)
            .Property(x => Sql.Property <string>(x, "Name"));

            using (var db = GetDataContext(context, ms))
                using (db.CreateLocalTable <DynamicColumnsTestFullTable>())
                {
                    var obj = new CustomSetterGetterBase {
                        Id = 5
                    };
                    storage.Add(5, new Dictionary <string, object>());
                    storage[5].Add("Name", "test_name");
                    db.Insert(obj);

                    var data = db.GetTable <CustomSetterGetterBase>().ToList();
                    Assert.AreEqual(1, data.Count);
                    Assert.AreEqual(5, data[0].Id);
                    Assert.AreEqual(0, data[0].SQLiteValues.Count);
                    Assert.AreEqual(0, data[0].Values.Count);
                    Assert.AreEqual(1, storage.Count);
                    Assert.AreEqual(5, storage.Keys.Single());
                    Assert.AreEqual(1, storage[5].Count);
                    Assert.AreEqual("Name", storage[5].Keys.Single());
                    Assert.AreEqual("test_name", storage[5]["Name"]);
                }
        }
Esempio n. 3
0
        static object Getter(IDictionary <int, Dictionary <string, object> > storage, CustomSetterGetterBase instance, string property, object defaultValue)
        {
            if (!storage.ContainsKey(instance.Id))
            {
                return(defaultValue);
            }

            if (!storage[instance.Id].TryGetValue(property, out var value))
            {
                value = defaultValue;
            }

            return(value);
        }