protected override PropertyDefinition _Clone() { ScalarPropertyDefinition prop = new ScalarPropertyDefinition(); CopyTo(prop); return(prop); }
public EntityPropertyDefinition(ScalarPropertyDefinition pd) { if (pd.PropertyType.Entity.GetPkProperties().Count() != 1) { throw new ArgumentException(string.Format("Entity {0} must have single primary key", pd.PropertyType.Identifier)); } InitFromScalar(this, pd); }
public override void CopyTo(PropertyDefinition to) { base.CopyTo(to); ScalarPropertyDefinition definition = (to as ScalarPropertyDefinition); if (definition != null) { definition._sf = _sf.Clone(); definition.SourceFieldAlias = SourceFieldAlias; } }
public ScalarPropertyDefinition ToPropertyDefinition() { if (SourceFields.Count() > 1) { throw new InvalidOperationException(string.Format("Cannot convert property {0} to PropertyDefinition", Identifier)); } var sf = SourceFields.First(); var p = new ScalarPropertyDefinition(Entity, Name) { SourceField = new SourceFieldDefinition(SourceFragment, sf.SourceFieldExpression, sf.SourceType, sf.SourceTypeSize, sf.IsNullable, false, sf.DefaultValue) }; CopyTo(p); return(p); }
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); }
internal static EntityPropertyDefinition FromScalar(ScalarPropertyDefinition pd) { return(InitFromScalar(new EntityPropertyDefinition(), pd)); }