コード例 #1
0
        public void TestDefaultConfigWithCustomKey()
        {
            var result = SimpleSaveConfiguration.GetEntityConfig <UserDto>().WithKey(x => x.MyCustomKey).AsDefault();

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Configuration.Key.Prop.Name, nameof(UserDto.MyCustomKey));
        }
コード例 #2
0
        public void TestDefaultConfigWithColumnName()
        {
            var result = SimpleSaveConfiguration.GetEntityConfig <UserDto>()
                         .WithKey(x => x.MyCustomKey).Column(x => x.MyCustomKey, "Id");

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Configuration.Key.ColumnName, "Id");
        }
コード例 #3
0
        public void TestGetDefaultConfig()
        {
            var result = SimpleSaveConfiguration.GetEntityConfig <UserDto>();

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Configuration.DtoType, typeof(UserDto));
            Assert.AreEqual(nameof(UserDto), result.Configuration.TableName);
        }
コード例 #4
0
        public TypePropertyMapEntryExt(
            Type type,
            string alias,
            int index,
            ISet <Type> typesWeCareAbout)
        {
            Type     = type;
            Metadata = SimpleSaveConfiguration.GetEntityConfig(type);
            Alias    = alias;
            Index    = index;
            foreach (var property in Metadata.Properties.Values.Where(p => !p.IsIgnored))
            {
                var key = property.Prop.PropertyType;
                if (property.IsEnumerable)
                {
                    var genericArguments = property.Prop.PropertyType.GenericTypeArguments;
                    if (genericArguments == null ||
                        genericArguments.Length != 1 ||
                        !typesWeCareAbout.Contains(genericArguments[0]) ||
                        !property.HasRelationship)
                    {
                        continue;
                    }

                    key = genericArguments[0];
                }
                else if (!typesWeCareAbout.Contains(key))
                {
                    if (property.HasAttribute <ForeignKeyReferenceAttribute>())
                    {
                        //  Value type back references are the only property types we support. If there's any kind of object
                        //  in there we ignore it for the purpose of back referencing. Basically, if something's marked with
                        //  one of SimpleSave's cardinality attributes we assume it's a forward reference; if it's not marked
                        //  with such a reference and it's not a value type then it's also not a supported foreign key column
                        //  type, so we can't do anything with it anyway.
                        if (!property.IsValueType && property.IsReferenceType)
                        {
                            continue;
                        }

                        var foreignKey = property.GetAttribute <ForeignKeyReferenceAttribute>();
                        key = foreignKey.ReferencedDto;
                        if (!typesWeCareAbout.Contains(key))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else if (!property.HasRelationship && !property.IsEnum)
                {
                    continue;
                }
            }
        }
コード例 #5
0
        public void TestDefaultConfigWithTypeParameter()
        {
            var result = SimpleSaveConfiguration.GetEntityConfig(typeof(UserDto));

            Assert.IsNotNull(result);
        }