0
由于我工作的地方迫使我使用存储过程,而且我还没有足够长的时间来阻止它,所以我已经为我们的所有存储过程定制了LiNQ to SQL代码生成。是的,这是正确的,我们已经存储了我们所有数据访问的程序,并且自我们没有表访问这意味着我们通常最终为所有“实体”提供3个类。现在,当我撞墙时,我正在完成最新的更改。如何通过运行时反射来获取重载?
下面的代码不起作用,原因是它自己调用,但我需要得到过载。其原因是,不可能跟踪40个参数,因此我在项目构建时生成一个“动态”类。
[Function(Name="dbo.user_insert")]
public IList<ProcedureResult> UserInsert(UserInsertObj userInsertObj)
{
IExecuteResult result = this.ExecuteMethodCall(this, (MethodInfo)MethodInfo.GetCurrentMethod(),
userInsertObj.UserId, userInsertObj.ProductId, userInsertObj.FromIp,
userInsertObj.CampaignName, userInsertObj.Campaign, userInsertObj.Login,
userInsertObj.Password, userInsertObj.Nickname, userInsertObj.Pin, userInsertObj.Language,
userInsertObj.Currency, userInsertObj.Country, userInsertObj.Region, userInsertObj.Birthday,
userInsertObj.FirstName, userInsertObj.MiddleName, userInsertObj.LastName,
userInsertObj.Address1, userInsertObj.Address2, userInsertObj.Address3, userInsertObj.Zip,
userInsertObj.City, userInsertObj.Timezone, userInsertObj.Email, userInsertObj.EmailNotify,
userInsertObj.Gender, userInsertObj.Phone, userInsertObj.MobileCc, userInsertObj.MobileNr,
userInsertObj.MobileModel, userInsertObj.Referral, userInsertObj.GroupId,
userInsertObj.StreetNumber, userInsertObj.StreetName);
return new List<ProcedureResult>
{
new ProcedureResult
{
Name = "userId",
Value = result.GetParameterValue(0),
Type = typeof(System.Nullable<System.Int32>)
}
};
}
我打得四处使用类似下面的,但不知道其超载使用和搜索MSDN我还没有接近任何有用的东西呢。
((MethodInfo)MethodInfo.GetCurrentMethod()).DeclaringType.GetMethod("", new Type[] {})
我将如何实现获得过载从CurrentMethod?
编辑:澄清,我们不允许使用数据库表。
似乎是一个bizare方法来调用使用LinqToSQL存储过程,你这样做知道你可以将它们映射到你的DataContext类的方法吗? – 2010-08-02 15:11:34
@本,谢谢!我已更新有关您的评论的问题。 – mhenrixon 2010-08-02 15:16:03
[如何使用反射调用.NET中的重载方法]的可能重复(http://stackoverflow.com/questions/223495/how-to-use-reflection-to-invoke-an-overloaded-method-in -净) – mhenrixon 2010-08-02 16:10:12