示例#1
0
        protected void Init(EntityBase Parent, string RelatedPropertyName, Type RelatedPropertyType)
        {
            _Parent = Parent;

            System.Reflection.PropertyInfo prop;
            if (RelatedPropertyType != null)
            {
                prop = Parent.GetType().GetProperty(RelatedPropertyName, RelatedPropertyType);
            }
            else
            {
                prop = Parent.GetType().GetProperty(RelatedPropertyName);
            }
            ForeignKey = ForeignKeyInfo.Create(prop);
            if (ForeignKey == null)
            {
                throw new MissingForeignKeyException(prop.DeclaringType, prop.Name);
            }

            list = new List <T>();
        }
示例#2
0
 /// <summary>
 /// Copies all private fields to the specified object.
 /// </summary>
 /// <param name="obj">An instance of EntityBase to copy data.</param>
 /// <remarks>You can only copy data to instances of the same type.</remarks>
 private void CopyTo(EntityBase obj)
 {
     if (obj.GetType() != this.GetType())
     {
         throw (new InvalidCastException());
     }
     System.Reflection.FieldInfo[] fields = this.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
     foreach (System.Reflection.FieldInfo field in fields)
     {
         field.SetValue(obj, field.GetValue(this));
     }
 }
示例#3
0
        private static ConditionCollection CreateDeleteConditions(EntityBase instance)
        {
            ConditionCollection conditions = new ConditionCollection();

            foreach (FieldInfo i in GetFields(instance.GetType()))
            {
                if (i.PrimaryKey)
                {
                    if (conditions.Count != 0)
                    {
                        conditions.Add(LogicalOperator.And);
                    }
                    conditions.Add(i.RelatedProperty.Name, i.PropertyValue(instance));
                }
            }
            if (conditions.Count == 0)
            {
                throw (new Tenor.Data.MissingPrimaryKeyException(instance.GetType()));
            }

            return(conditions);
        }