public T GetDetail(object id) { //var objectProxy = new ObjectProxy(Model); var dbContext = new dbContext(SqlCon, this.ConFac); var objectProxy = dbContext.GetDetail(Model, id, true); if (objectProxy.IsLoad == LoadType.NoObj) { return(default(T)); } return((T) new ModelHelper(this.ConFac).GetFromProxy(objectProxy)); }
/// <summary> /// 执行外部模型的操作 /// </summary> /// <param name="model">外部的模型</param> /// <param name="operation">外部的模型的操作</param> /// <param name="arg">参数 arg的Model为源模型</param> /// <param name="id">外部模型的ID</param> /// <returns>生成的ObjectProxy</returns> public IObjectProxy ExcuteOperation(Model model, IOperation operation, IObjectProxy arg, object id) { //如果为空,返回默认值 //明天个性 //Set Value 如果为BusinisObject 返回默认值 ~~~ 笨的!!!! #region 初始化要操作的值,即要返回的值resultProxy var db = new SqlServer.dbContext((model.SqlCon == null ? model.Module.SqlCon : model.SqlCon), this.ContextFac); IObjectProxy resultproxy = null; if (operation == null) { return(db.GetDetail(model, id)); } List <object> invokeparams = new List <object>(); switch (operation.BaseOperationType) { case BaseOperationType.Create: resultproxy = new SqlDataProxy(model, this.ContextFac, LoadType.Null, this.Con); break; case BaseOperationType.Delete: case BaseOperationType.Update: resultproxy = db.GetDetail(model, id); break; default: return(null); } #endregion foreach (var command in operation.GetCommands().OrderBy(p => p.Index)) { switch (command.CommandsType) { case CommandsType.SetAccess: resultproxy.NotifyPropertyCanSet(command.Property, System.Convert.ToBoolean(command.Exp)); break; case CommandsType.SetValue: resultproxy[command.Property] = GetValue(command.Property, arg, command.Exp); break; case CommandsType.ExuteProprtyModelMethod: DynamicObject proxy = resultproxy[command.Property] as DynamicObject; object ob1 = new object(); proxy.TryInvokeMember(new ObjectInvokeMemberBinder(command.Exp), new object[] { } , out ob1); break; case CommandsType.ExuteOutModelMethod: var desmodel = this.ExcuteOperation( command.ArgModel, command.ArgModel.Operations.FirstOrDefault(p => p.Name.Trim().ToUpper() == command.Exp.Trim().ToUpper()), resultproxy, GetValue(command.Property, resultproxy, command.ArgSourceIdExp)); if (desmodel != null && command.Property != null) { resultproxy[command.Property] = GetValue(command.Property, desmodel, command.ArgPropertyExp); } break; case CommandsType.Filter: CheckCommand(command, resultproxy); break; default: break; } } var db2 = new SqlServer.dbContext((model.SqlCon == null ? model.Module.SqlCon : model.SqlCon), this.ContextFac); switch (operation.BaseOperationType) { case BaseOperationType.Create: db2.Create(resultproxy); break; case BaseOperationType.Delete: db2.Delete(resultproxy); break; case BaseOperationType.Update: db2.Save(resultproxy); break; default: break; } return(resultproxy); }