views:

27

answers:

1

Hi,

Since where I work force me to use stored procedures and I haven't been around long enough to prevent it I have customized LiNQ to SQL code generation for all our stored procedures. Yes that's right we have stored procedures for ALL our data access and since we don't have table access it means that we often end up with 3 classes for all "entities". Now, I am drawing near completion of the latest changes when I hit a wall.

The following code does not work and the reason being that it is calling itself but I need to get the overload. The reason for this is that it's fucking impossible to keep track of 40 parameters so I generate a "dynamic" class when the project builds.

[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>) 
        }
    };
}

I played around with using something like the below but have no idea which overload to use and searching MSDN I haven't come close to anything useful yet.

((MethodInfo)MethodInfo.GetCurrentMethod()).DeclaringType.GetMethod("", new Type[] {})

How would I achieve getting the overload from the CurrentMethod?

EDIT: clarified that we are not allowed to use the database tables.

A: 

I forgot about linq! In this particular scenario I have only two methods one containing 1 parameter and one containing all the other parameters so a simple (see below) works fine:

method.DeclaringType.GetMethods()
    .Where(x => x.Name == "UserInsert" 
           && x.GetParameters().Count() > 1)
    .Single()
mhenrixon