public static T Clone <T>(T source) where T : IEntityState, new() { T item = new T(); Mappings.ObjectMapper om = Mappings.ObjectMapper.GetOM(typeof(T)); OnClone(source, item, om); return(item); }
public static int SaveAsClone(IConnectinContext cc, Mappings.DataObject data) { Type type = data.GetType(); Mappings.ObjectMapper om = Mappings.ObjectMapper.GetOM(type); Mappings.DataObject result = (Mappings.DataObject)Activator.CreateInstance(type); OnClone(data, result, om); return(Save(cc, result)); }
internal static object Load(Type type, object id, IConnectinContext cc) { Mappings.ObjectMapper om = Mappings.ObjectMapper.GetOM(type); Mappings.SelectDataReader sr = om.GetSelectReader(type); if (om.ID == null) { throw new PeanutException(DataMsg.ID_MAP_NOTFOUND); } Expression exp = new Expression(); exp.SqlText.Append(om.ID.ColumnName + "=@p1"); exp.Parameters.Add(new Command.Parameter { Name = "p1", Value = id }); return(EntityBase.ExOnListFirst(type, cc, om.GetSelectTable(sr), exp, null, null)); }
public static IList <Validates.ValidaterError> Verify(object data, IConnectinContext cc) { Mappings.ObjectMapper om = Mappings.ObjectMapper.GetOM(data.GetType()); List <Validates.ValidaterError> errors = new List <Validates.ValidaterError>(om.Properties.Count); for (int i = 0; i < om.Properties.Count; i++) { PropertyMapper pm = om.Properties[i]; object value = pm.Handler.Get(data); for (int k = 0; k < pm.Validaters.Length; k++) { Validates.ValidaterAttribute val = pm.Validaters[k]; if (!val.Validating(value, data, pm, cc)) { errors.Add(new Validates.ValidaterError { Name = pm.ColumnName, Error = val.Message }); } } } return(errors); }
private static void OnClone(object source, object newobj, Mappings.ObjectMapper om) { object value = null; Mappings.PropertyMapper pm = om.ID; if (pm != null) { value = pm.Handler.Get(source); if (value != null) { pm.Handler.Set(newobj, value); } } for (int i = 0; i < om.Properties.Count; i++) { Mappings.PropertyMapper p = om.Properties[i]; value = p.Handler.Get(source); if (value != null) { p.Handler.Set(newobj, value); } } }