Ejemplo n.º 1
0
        internal void InitInheritanceMapping()
        {
            var mappingAttrs = _mappingSchema.GetAttributes <InheritanceMappingAttribute>(ObjectType, a => a.Configuration, false);
            var result       = new List <InheritanceMapping>(mappingAttrs.Length);

            if (mappingAttrs.Length > 0)
            {
                foreach (var m in mappingAttrs)
                {
                    var mapping = new InheritanceMapping
                    {
                        Code      = m.Code,
                        IsDefault = m.IsDefault,
                        Type      = m.Type,
                    };

                    var ed = _mappingSchema.GetEntityDescriptor(mapping.Type);

                    foreach (var column in ed.Columns)
                    {
                        if (Columns.All(f => f.MemberName != column.MemberName))
                        {
                            Columns.Add(column);
                        }

                        if (column.IsDiscriminator)
                        {
                            mapping.Discriminator = column;
                        }
                    }

                    result.Add(mapping);
                }

                var discriminator = result.Select(m => m.Discriminator).FirstOrDefault(d => d != null);

                if (discriminator == null)
                {
                    throw new LinqException("Inheritance Discriminator is not defined for the '{0}' hierarchy.", ObjectType);
                }

                foreach (var mapping in result)
                {
                    if (mapping.Discriminator == null)
                    {
                        mapping.Discriminator = discriminator;
                    }
                }
            }

            if (_inheritanceMappings == null)
            {
                _inheritanceMappings = result;
                _mre.Set();
            }
        }
Ejemplo n.º 2
0
        internal void InitInheritanceMapping()
        {
            var mappingAttrs = _mappingSchema.GetAttributes<InheritanceMappingAttribute>(ObjectType, a => a.Configuration, false);

            InheritanceMapping = new List<InheritanceMapping>(mappingAttrs.Length);

            if (mappingAttrs.Length > 0)
            {
                foreach (var m in mappingAttrs)
                {
                    var mapping = new InheritanceMapping
                    {
                        Code      = m.Code,
                        IsDefault = m.IsDefault,
                        Type      = m.Type,
                    };

                    var ed = _mappingSchema.GetEntityDescriptor(mapping.Type);

                    foreach (var column in ed.Columns)
                    {
                        if (Columns.All(f => f.MemberName != column.MemberName))
                            Columns.Add(column);

                        if (column.IsDiscriminator)
                            mapping.Discriminator = column;
                    }

                    InheritanceMapping.Add(mapping);
                }

                var discriminator = InheritanceMapping.Select(m => m.Discriminator).FirstOrDefault(d => d != null);

                if (discriminator == null)
                    throw new LinqException("Inheritance Discriminator is not defined for the '{0}' hierarchy.", ObjectType);

                foreach (var mapping in InheritanceMapping)
                    if (mapping.Discriminator == null)
                        mapping.Discriminator = discriminator;
            }
        }