SqlServer and MySql
This commit is contained in:
1 parent
011e60afa9
commit
23e8615462
1 file changed
+78
-2
@@ -101,10 +101,11 @@ namespace @namespaceObject.Namespace@{<text>.Entity</text>}
|
|||||||
</text>
|
</text>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ProviderName { get; set; }
|
||||||
|
|
||||||
public static @sysTableSchemas[0].TableName.StringToProerty()Entity GetInstance()
|
public static @sysTableSchemas[0].TableName.StringToProerty()Entity GetInstance(string providerName)
|
||||||
{
|
{
|
||||||
return new @sysTableSchemas[0].TableName.StringToProerty()Entity();
|
return new @sysTableSchemas[0].TableName.StringToProerty()Entity() { ProviderName = providerName };
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void CopyFrom(@sysTableSchemas[0].TableName.StringToProerty()Entity source)
|
public virtual void CopyFrom(@sysTableSchemas[0].TableName.StringToProerty()Entity source)
|
||||||
@@ -145,16 +146,71 @@ namespace @namespaceObject.Namespace@{<text>.Entity</text>}
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string GetSelectFrom()
|
public override string GetSelectFrom()
|
||||||
|
{
|
||||||
|
if (ProviderName.Contains("MySql"))
|
||||||
|
{
|
||||||
|
return GetSelectFromByMySql();
|
||||||
|
}
|
||||||
|
else if (ProviderName.Contains("SqlServer"))
|
||||||
|
{
|
||||||
|
return GetSelectFromByBySqlServer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string GetSelectFromByMySql()
|
||||||
|
{
|
||||||
|
return $" select {DB_NAME_FIELDS} from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} with(nolock) ";
|
||||||
|
}
|
||||||
|
public string GetSelectFromByBySqlServer()
|
||||||
{
|
{
|
||||||
return $" select {DB_NAME_FIELDS} from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} ";
|
return $" select {DB_NAME_FIELDS} from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} ";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetSelectCountFrom(string sqlWhere)
|
public override string GetSelectCountFrom(string sqlWhere)
|
||||||
|
{
|
||||||
|
if (ProviderName.Contains("MySql"))
|
||||||
|
{
|
||||||
|
return GetSelectCountFromByMySql(sqlWhere);
|
||||||
|
}
|
||||||
|
else if (ProviderName.Contains("SqlServer"))
|
||||||
|
{
|
||||||
|
return GetSelectCountFromBySqlServer(sqlWhere);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetSelectCountFromByMySql(string sqlWhere)
|
||||||
{
|
{
|
||||||
return $" select count(*) from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} where 1=1 {sqlWhere}";
|
return $" select count(*) from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} where 1=1 {sqlWhere}";
|
||||||
}
|
}
|
||||||
|
public string GetSelectCountFromBySqlServer(string sqlWhere)
|
||||||
|
{
|
||||||
|
return $" select count(*) from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} with(nolock) where 1=1 {sqlWhere}";
|
||||||
|
}
|
||||||
|
|
||||||
public override string GetSelectTopFrom(int limit, int start, string orderby, string orderbytag, string sqlWhere)
|
public override string GetSelectTopFrom(int limit, int start, string orderby, string orderbytag, string sqlWhere)
|
||||||
|
{
|
||||||
|
if (ProviderName.Contains("MySql"))
|
||||||
|
{
|
||||||
|
return GetSelectTopFromByMySql(limit, start, orderby, orderbytag, sqlWhere);
|
||||||
|
}
|
||||||
|
else if (ProviderName.Contains("SqlServer"))
|
||||||
|
{
|
||||||
|
return GetSelectTopFromBySqlServer(limit, start, orderby, orderbytag, sqlWhere);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotSupportedException($"不支持的数据库提供程序:{ProviderName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetSelectTopFromByMySql(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
||||||
@for (var i = 0; i < sysTableSchemas.Length; i++)
|
@for (var i = 0; i < sysTableSchemas.Length; i++)
|
||||||
@@ -174,6 +230,26 @@ namespace @namespaceObject.Namespace@{<text>.Entity</text>}
|
|||||||
return $" select {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} where 1=1 {sqlWhere} ) a where num> {offset} LIMIT {offset},{limit} ";
|
return $" select {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} where 1=1 {sqlWhere} ) a where num> {offset} LIMIT {offset},{limit} ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetSelectTopFromBySqlServer(int limit, int start,string orderby,string orderbytag, string sqlWhere)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(orderbytag) || orderbytag.Trim() != "desc") orderbytag = "asc";
|
||||||
|
@for (var i = 0; i < sysTableSchemas.Length; i++)
|
||||||
|
{
|
||||||
|
if (@sysTableSchemas[i].Pk > 0)
|
||||||
|
{
|
||||||
|
<text> if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_@sysTableSchemas[i].FieldName.ToUpper() ; </text>
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@if(sysTableSchemas.Sum(x=>x.Pk)==0)
|
||||||
|
{
|
||||||
|
<text> if (string.IsNullOrEmpty(orderby) || !DB_NAME_FIELDS.Contains(orderby)) orderby = DB_@sysTableSchemas[0].FieldName.ToUpper() ; </text>
|
||||||
|
}
|
||||||
|
string top = limit > 0 ? $"top {limit}" : "";
|
||||||
|
return $" select {top} {DB_NAME_FIELDS} from (select {DB_NAME_FIELDS} ,row_number() over(order by {orderby} {orderbytag}) as num from { DB_NAME_@sysTableSchemas[0].TableName.ToUpper()} with(nolock) where 1=1 {sqlWhere} ) a where num> {limit * (start - 1)}";
|
||||||
|
}
|
||||||
|
|
||||||
public @sysTableSchemas[0].TableName.StringToProerty()Entity Clone()
|
public @sysTableSchemas[0].TableName.StringToProerty()Entity Clone()
|
||||||
{
|
{
|
||||||
@sysTableSchemas[0].TableName.StringToProerty()Entity result = new @sysTableSchemas[0].TableName.StringToProerty()Entity();
|
@sysTableSchemas[0].TableName.StringToProerty()Entity result = new @sysTableSchemas[0].TableName.StringToProerty()Entity();
|
||||||
|
|||||||
Reference in new issue
Block a user