public virtual IPropertyMapInfo GetPrimaryKeyNeedBinding <T>() { var map = _cache.GetMapInfo(typeof(T), true); if (map.PrimaryKeyGenerate == PrimaryKeyGenerate.Auto) { if (map.PKStatus == PrimaryKeyStatus.Single) { return(map.PrimaryKeyMaps.First()); } else { GenerateExceptionHelper.ThrowPrimaryKeyDefineNotSupport(typeof(T)); } } return(null); }
public virtual string Remove <T>(T entity) { var map = _cache.GetMapInfo(typeof(T), true); if (map.PrimaryKeyMaps.Count() == 0) { GenerateExceptionHelper.ThrowNoPrimaryKeyDefine(typeof(T)); } try { StringBuilder str = new StringBuilder(); str.Append(_tr.Delete).Append(_tr.GetEscapedTableName(map.Table.LocalName)); str.Append(_tr.Where).Append(_cb.BuildWherePrimaryKey(map, entity)); return(str.ToString()); } catch (Exception ex) { throw ex.CreateWrapException <SQLGenerateException>(); } }
public virtual string FindByPK <T>(T pk) { pk.ThrowIfNullArgument(nameof(pk)); var map = _cache.GetMapInfo(typeof(T), true); if (map.PrimaryKeyMaps.Count() == 0) { GenerateExceptionHelper.ThrowNoPrimaryKeyDefine(typeof(T)); } try { StringBuilder str = new StringBuilder(); str.Append(_tr.Select).Append(_cb.BuildSelectColumns(map)).Append(_tr.From).Append(_tr.GetEscapedTableName(map.Table.LocalName)); str.Append(_tr.Where).Append(_cb.BuildWherePrimaryKey(map, pk)); return(str.ToString()); } catch (Exception ex) { throw ex.CreateWrapException <SQLGenerateException>(); } }