private SqlCommand BuildCommandFromTypeMap(IRelatable relatee, ORMTypeMapping typeMap, string relationKey) { // Logger.Write( MethodBase.GetCurrentMethod() ); ORMCommandMap ocm = typeMap.GetMapByName(relationKey); if (ocm != null) { SqlCommand cmd = new SqlCommand(ocm.StoredProcedure, conn); cmd.CommandType = CommandType.StoredProcedure; foreach (object ob in ocm.PropertyMaps) { ORMPropertyMap propMap = (ORMPropertyMap)ob; SqlParameter newParam = CreateParameterFromPropertyMap(propMap); if ((newParam.Direction == ParameterDirection.Input) || (newParam.Direction == ParameterDirection.InputOutput)) { SetParameterValue(newParam, relatee, propMap.MemberName); } cmd.Parameters.Add(newParam); } return(cmd); } else { //ExceptionPolicy.HandleException( new NullReferenceException("No such command mapping: " + typeMap.FullName + ":" + relationKey), "Exception" ); } return(null); }
private void AssignOutputValuesToObject(SqlCommand cmd, IRelatable relatee, ORMTypeMapping typeMap, string relationKey) { // Logger.Write( MethodBase.GetCurrentMethod() ); ORMCommandMap ocm = typeMap.GetMapByName(relationKey); foreach (object ob in ocm.PropertyMaps) { ORMPropertyMap propMap = (ORMPropertyMap)ob; if ((propMap.DataDirection == ParameterDirection.Output) || (propMap.DataDirection == ParameterDirection.InputOutput)) { PropertyInfo prop; Type t = relatee.GetType(); prop = t.GetProperty(propMap.MemberName); if (prop != null) { if (cmd.Parameters[propMap.Parameter].Value != DBNull.Value) { prop.SetValue(relatee, cmd.Parameters[propMap.Parameter].Value, null); } } else { // ExceptionPolicy.HandleException( new NullReferenceException(("Missing member " + t.FullName + "." + propMap.MemberName)), "Exception" ); } } } }
private SqlParameter CreateParameterFromPropertyMap(ORMPropertyMap propMap) { //Logger.Write( MethodBase.GetCurrentMethod() ); SqlParameter param = new SqlParameter(); param.ParameterName = propMap.Parameter; param.SqlDbType = propMap.SqlDataType; param.Direction = propMap.DataDirection; if (propMap.Size != -1) { param.Size = propMap.Size; } return(param); }
public ORMCommandMap(XmlNode cmdMap) { string multiple; propertyMaps = new ArrayList(); relationKey = cmdMap.Attributes["type"].Value; storedProcedure = cmdMap.Attributes["storedproc"].Value; multiple = cmdMap.Attributes["multiple"].Value.ToUpper(); returnsMultiple = ((multiple == "TRUE") || (multiple == "YES")); foreach (XmlNode propertyMap in cmdMap.ChildNodes) { ORMPropertyMap propMap = new ORMPropertyMap(propertyMap); propertyMaps.Add(propMap); } }