Exemple #1
0
        protected override PropertyDefinition _Clone()
        {
            EntityPropertyDefinition prop = new EntityPropertyDefinition();

            CopyTo(prop);
            return(prop);
        }
Exemple #2
0
        public override void CopyTo(PropertyDefinition to)
        {
            base.CopyTo(to);
            EntityPropertyDefinition property = (to as EntityPropertyDefinition);

            if (property != null)
            {
                foreach (SourceField sf in _fields)
                {
                    property._fields.Add(sf);
                }
            }
        }
Exemple #3
0
        internal static EntityPropertyDefinition InitFromScalar(EntityPropertyDefinition ed, ScalarPropertyDefinition pd)
        {
            if (!pd.PropertyType.IsEntityType)
            {
                throw new ArgumentException(string.Format("EntityProperty type must be a entity type. Passed {0}", pd.PropertyType.Identifier));
            }

            pd.CopyTo(ed);
            ed._sf = pd.SourceFragment;
            var    pks       = pd.PropertyType.Entity.GetPkProperties();
            string propAlias = null;

            if (pks.Count() != 0)
            {
                propAlias = pks.First().PropertyAlias;
            }

            SourceField field = new SourceField(
                propAlias,
                ed._sf, pd.SourceFieldExpression, pd.SourceTypeSize, pd.IsNullable, pd.SourceType,
                pd.SourceField.DefaultValue, pd.SourceFieldAlias
                );

            ed._fields.Add(field);

            if (string.IsNullOrEmpty(propAlias))
            {
                EntityDefinition.PropertyAddedDelegate d = null;
                d = (e, p) =>
                {
                    if (p.HasAttribute(Field2DbRelations.PK))
                    {
                        field.PropertyAlias = p.PropertyAlias;
                        e.PropertyAdded    -= d;
                    }
                };
                pd.PropertyType.Entity.PropertyAdded += d;
            }
            return(ed);
        }