/// <summary> /// 根据查询条件,返回一个查询对象。一般用于参数化查询。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="condition">查询条件</param> /// <returns>返回查询对象xQuery,可以进一步参数化赋值,并得到结果</returns> public static xQuery <T> find <T>(String condition) where T : IEntity { ObjectInfo state = new ObjectInfo(typeof(T)); Query q = ObjectDb.Find(state, condition); return(new xQuery <T>(q)); }
// The persistence layer will scope data it saves to the player. This is done on the server side // and is transparent to the client. This is a convenience feature for prototyping and development. Do // not use this in a production app. // **IMPORTANT** // Please note that this is still not completely secure, as a hacked client can still write out data // you are not expecting and there is no way to validate the data before saving it (other then the scoping). Any server logic that // you write that depends on data saved using this feature is WRONG. Do not do that. You have been warned. void Start() { //Setup. The following 3 steps are required for peristence to work // 1. Find the ObjectDb actor. It is started automatically by the actor system ObjectDb db = ActorSystem.Instance.Find("ObjectDb") as ObjectDb; // 2. Set the callback to receive objects from the server ObjectDb.ObjectReceived callback = OnObjectReceived; db.OnObjectReceived(callback); // 3. Set the player id db.SetPlayerId(User.Instance.username); // Saving and retrieving entities Entity entity = new Entity(); entity.id = "dbtest"; db.Save(entity); db.Find(entity.id); // If you want to save arbitrary binary data, you must wrap it in a NativeBytes message and attach that // message to the entity you are saving. // Simple byte array to use as a test string str = "Howdy"; byte[] bytes = new byte[str.Length * sizeof(char)]; System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); // Wrap the byte array and save it NativeBytes nativeBytes = new NativeBytes(); nativeBytes.bytes = bytes; entity.nativeBytes = nativeBytes; entity.id = "native_bytes_test"; db.Save(entity); db.Find(entity.id); }
public static IList FindDataOther(Type throughType, Type t, String order, int id) { // 1029 ObjectInfo state = new ObjectInfo(throughType); String relationPropertyName = state.EntityInfo.GetRelationPropertyName(t); EntityPropertyInfo info = state.EntityInfo.FindRelationProperty(t); state.Order = order; state.include(info.Name); return(ObjectDb.Find(state, relationPropertyName + ".Id=" + id).listChildren(info.Name)); }
public static String GetSameTypeIds(Type throughType, Type t, int id) { // 1029 ObjectInfo state = new ObjectInfo(throughType); String relationPropertyName = state.EntityInfo.GetRelationPropertyName(t); EntityPropertyInfo info = state.EntityInfo.FindRelationProperty(t); String ids = ObjectDb.Find(state, relationPropertyName + ".Id=" + id).get(info.Name + ".Id"); EntityPropertyInfo property = state.EntityInfo.GetProperty(relationPropertyName); String sql = String.Format("select distinct {0} from {1} where {2} in ({3}) and {0}<>{4}", property.ColumnName, state.EntityInfo.TableName, info.ColumnName, ids, id); IDbCommand command = DataFactory.GetCommand(sql, DbContext.getConnection(state.EntityInfo)); IDataReader rd = null; StringBuilder builder = new StringBuilder(); try { rd = command.ExecuteReader(); while (rd.Read()) { builder.Append(rd[0]); builder.Append(","); } } catch (Exception exception) { logger.Error(exception.Message); throw exception; } finally { if (command.Connection.State != ConnectionState.Closed) { command.Connection.Close(); command.Connection.Dispose(); OrmHelper.clostCount++; LogManager.GetLogger("Class:System.ORM.Operation.FindRelationOperation Method:GetSameTypeIds").Info("数据库连接已关闭【" + OrmHelper.clostCount + "】"); } OrmHelper.CloseDataReader(rd); } return(builder.ToString().TrimEnd(',')); }