Skip to content

添加一些函数 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
添加一些函数
  • Loading branch information
jianliulin committed Sep 20, 2018
commit 30c870283146ada933f66e7b2bf31d51cb9082ba
Binary file added .vs/Dos.ORM/v15/.suo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
Binary file modified Dos.ORM.Standard/.vs/Dos.ORM/v15/.suo
Binary file not shown.
Binary file modified Dos.ORM.Standard/.vs/Dos.ORM/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 38 additions & 3 deletions Dos.ORM.Standard/Dos.ORM/Common/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -140,6 +141,9 @@ public class Entity
/// 实体状态
/// </summary>
private EntityState _entityState = EntityState.Unchanged;


public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// select *。用于Lambda写法实现 select * 。注:表中不得含有字段名为All。
/// </summary>
Expand Down Expand Up @@ -185,10 +189,19 @@ public virtual bool V1_10_5_6_Plus()
/// </summary>
public Entity()
{
var tbl = GetType().GetCustomAttribute<Table>(false) as Table;
_tableName = tbl != null ? tbl.GetTableName() : GetType().Name;
_userName = tbl != null ? tbl.GetUserName() : "";
var type = GetType();
if (type.IsGenericType)
{
type = type.GetGenericArguments().First();
}

var tbl = type.GetCustomAttribute<Table>(false);
_tableName = tbl?.GetTableName() ?? type.Name;
_userName = tbl?.GetUserName();

_isAttached = true;

PropertyChanged = EntityPropertyChanged;
}
/// <summary>
/// 构造函数
Expand Down Expand Up @@ -443,5 +456,27 @@ public string GetTableAsName()
{
return _tableAsName;
}

private void EntityPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (_isAttached && GetFields().Count(a => a.PropertyName == e.PropertyName) == 1 && !_modifyFieldsStr.Contains(e.PropertyName))
{

_modifyFieldsStr.Add(e.PropertyName);
}
}

public void AddModifyField(string fieldName)
{
if (GetFields().Count(a => a.PropertyName == fieldName) == 1)
{
_modifyFieldsStr.Add(fieldName);
}
}

public virtual Field[] GetJoinFields()
{
return null;
}
}
}
39 changes: 36 additions & 3 deletions Dos.ORM.Standard/Dos.ORM/Common/EntityCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* 备注描述:
*******************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;

namespace Dos.ORM
{
/// <summary>
Expand Down Expand Up @@ -70,14 +73,15 @@ public static string GetUserName<TEntity>()
{
return getTEntity<TEntity>().GetUserName();
}

/// <summary>
/// 返回T
/// </summary>
/// <returns></returns>
private static TEntity getTEntity<TEntity>()
where TEntity : Entity
public static TEntity getTEntity<TEntity>() where TEntity : Entity
{
var typestring = typeof(TEntity).ToString();
var type = typeof(TEntity);
var typestring = type.IsGenericType ? "Entity<" + type.GetGenericArguments().First().FullName + ">" : type.FullName;

if (_entityList.ContainsKey(typestring))
return (TEntity)_entityList[typestring];
Expand All @@ -94,6 +98,35 @@ private static TEntity getTEntity<TEntity>()
}


public static Entity getTEntity(Type type)
{
if (!type.IsSubclassOf(typeof(Entity))) return default(Entity);

var typestring = type.IsGenericType ? "Entity<" + type.GetGenericArguments().First().FullName + ">" : type.FullName;

if (_entityList.ContainsKey(typestring))
return (Entity)_entityList[typestring];

lock (LockObj)
{
try
{
if (_entityList.ContainsKey(typestring))
return (Entity)_entityList[typestring];
var t = (Entity)Activator.CreateInstance(type);
_entityList.Add(typestring, t);
return t;
}
catch (Exception ext)
{
var sssss = ext.Message;
return default(Entity);

}
}
}


/// <summary>
/// 获取主键字段
/// </summary>
Expand Down
201 changes: 201 additions & 0 deletions Dos.ORM.Standard/Dos.ORM/Common/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Dos.ORM.Common;
using Dos;
using Dos.ORM;
using System.Reflection;

namespace Dos.ORM
{
Expand Down Expand Up @@ -1548,6 +1549,206 @@ public static int Len(this object key)
{
throw new Exception(string.Format(Tips, "Len"));
}

public static bool GreaterThan(this string field, string value)
{
throw new Exception(string.Format(Tips, "GreaterThan"));
}

public static bool GreaterOrEqual(this string field, string value)
{
throw new Exception(string.Format(Tips, "GreaterOrEqual"));
}

public static bool LessThan(this string field, string value)
{
throw new Exception(string.Format(Tips, "LessThan"));
}

public static bool LessOrEqual(this string field, string value)
{
throw new Exception(string.Format(Tips, "LessOrEqual"));
}

public static bool NotEqual(this string field, string value)
{
throw new Exception(string.Format(Tips, "NotEqual"));
}

/// <summary>
/// startIndex 以1开始
/// </summary>
/// <param name="field"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool SubGreaterThan(this string field, int startIndex, int length, string value)
{
throw new Exception(string.Format(Tips, "SubGreaterThan"));
}

/// <summary>
/// startIndex 以1开始
/// </summary>
/// <param name="field"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool SubGreaterOrEqual(this string field, int startIndex, int length, string value)
{
throw new Exception(string.Format(Tips, "SubGreaterOrEqual"));
}

/// <summary>
/// startIndex 以1开始
/// </summary>
/// <param name="field"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool SubLessThan(this string field, int startIndex, int length, string value)
{
throw new Exception(string.Format(Tips, "SubLessThan"));
}

/// <summary>
/// startIndex 以1开始
/// </summary>
/// <param name="field"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool SubLessOrEqual(this string field, int startIndex, int length, string value)
{
throw new Exception(string.Format(Tips, "SubLessOrEqual"));
}

/// <summary>
/// startIndex 以1开始
/// </summary>
/// <param name="field"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool SubNotEqual(this string field, int startIndex, int length, string value)
{
throw new Exception(string.Format(Tips, "SubNotEqual"));
}


/// <summary>
/// startIndex 以1开始
/// </summary>
/// <param name="field"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <param name="value"></param>
/// <returns></returns>

public static bool SubEqual(this string field, int startIndex, int length, string value)
{
throw new Exception(string.Format(Tips, "SubEqual"));
}

/// <summary>
/// startIndex 以1开始
/// where field not in (string,string,string)。传入Array或List&lt;string>。
/// </summary>
/// <param name="field"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <param name="values"></param>
/// <returns></returns>
public static bool SubIn(this string field, int startIndex, int length, params string[] values)
{
throw new Exception(string.Format(Tips, "SubIn"));
}

/// <summary>
/// startIndex 以1开始
/// where field not in (string,string,string)。传入Array或List&lt;string>。
/// </summary>
/// <param name="field"></param>
/// <param name="startIndex"></param>
/// <param name="length"></param>
/// <param name="values"></param>
/// <returns></returns>
public static bool SubNotIn(this string field, int startIndex, int length, List<string> values)
{
throw new Exception(string.Format(Tips, "SubNotIn"));
}


public static bool BitwiseAND(this int field, int value)
{
throw new Exception(string.Format(Tips, "BitwiseAND"));
}

public static bool BitwiseIN(this int field, int value)
{
throw new Exception(string.Format(Tips, "BitwiseIN"));
}

public static bool BitwiseOR(this int field, int value)
{
throw new Exception(string.Format(Tips, "BitwiseOR"));
}


public static bool BitwiseAND(this System.Enum field, int value)
{
throw new Exception(string.Format(Tips, "BitwiseAND"));
}


public static bool BitwiseOR(this System.Enum field, int value)
{
throw new Exception(string.Format(Tips, "BitwiseOR"));
}

public static bool BitwiseIN(this System.Enum field, int value)
{
throw new Exception(string.Format(Tips, "BitwiseIN"));
}

public static bool BitwiseAND(this System.Enum field, System.Enum value)
{
throw new Exception(string.Format(Tips, "BitwiseAND"));
}


public static bool BitwiseOR(this System.Enum field, System.Enum value)
{
throw new Exception(string.Format(Tips, "BitwiseOR"));
}


public static bool BitwiseIN(this System.Enum field, System.Enum value)
{
throw new Exception(string.Format(Tips, "BitwiseIN"));
}


public static bool LenEqual(this string field, int len)
{
throw new Exception(string.Format(Tips, "LenEqual"));
}

public static T GetAttribute<T>(this MemberInfo memberInfo) where T : Attribute
{
return memberInfo.GetCustomAttribute<T>(false);
//var customAttributes = memberInfo.GetCustomAttribute<T>(false);
//if (customAttributes == null || customAttributes.Length == 0)
//{
// return null;
//}
//return customAttributes[0] as T;
}
}
}

15 changes: 12 additions & 3 deletions Dos.ORM.Standard/Dos.ORM/Db/DbSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,19 @@ public DbSession(string assemblyName, string className, string connStr)
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <returns></returns>
public FromSection<TEntity> From<TEntity>(string asName = "")
where TEntity : Entity
//public FromSection<TEntity> From<TEntity>(string asName = "")
// where TEntity : Entity
//{
// return new FromSection<TEntity>(db, null, asName);
//}

public FromSection<TEntity> From<TEntity>(DbTrans trans = null, string asName = "") where TEntity : Entity
{
return new FromSection<TEntity>(db, null, asName);
if (trans == null)
{
return new FromSection<TEntity>(db, null, asName);
}
return new FromSection<TEntity>(db, trans, asName);
}

/// <summary>
Expand Down
Loading