fluentdata的ExpandoObject异常

by kevin 4. 六月 2013 21:42 >

现在开发的项目中使用fluentdata进行数据访问,简单易用,但是,也是有坑爹的bug。

先记录2个:

1 IStoredProcedureBuilderDynamic StoredProcedure(string storedProcedureName, ExpandoObject item) 参数类型明明是ExpandoObject,还是需要做一次显示转换。

A.  Bad

   1: var command = DefaultContext.StoredProcedure("InsertSPName", Entity)
   2:                     .AutoMap().ParameterOut("EntityId", DataTypes.Int32, 4);
   3:             command.Execute();
   4:             return command.ParameterValue<int>("EntityId");

B.  OK

   1: var command = DefaultContext.StoredProcedure("InsertSPName", (ExpandoObject)DanymicObject)
   2:         .AutoMap().ParameterOut("EntityId", DataTypes.Int32, 4);
   3: command.Execute();
   4: return command.ParameterValue<int>("EntityId");

2. IStoredProcedureBuilder Parameter(string name, object value);

参数类型是object , 但是如果传入的参数是ExpandoObject的一个属性,返回值就变成object了。需要将传入的参数显示转换成简单类型。

A. Bad

   1: public int Update(dynamic entity)
   2: {
   3:     IStoredProcedureBuilder iStoredProcedureBuilder = DefaultContext.StoredProcedure("EntityUpdate")
   4:            .Parameter("Title", entity.Title)
   5:            .Parameter("Entity_Id", entity.EntityId);
   6:     return iStoredProcedureBuilder.Execute();
   7: }

B. OK

   1: public int Update(dynamic entity)
   2: {
   3:     IStoredProcedureBuilder iStoredProcedureBuilder = DefaultContext.StoredProcedure("EntityUpdate")
   4:            .Parameter("Title", entity.Title as string)
   5:            .Parameter("Entity_Id", (int)entity.EntityId);
   6:     return iStoredProcedureBuilder.Execute();
   7: }
分享到: 更多