2

このようにすることもできますが、もっとうまくやる方法があるはずです。

    Resource.ResourceIncrease resource = new Resource.ResourceIncrease();

    using (IDbConnection connection = OpenConnection())
    {
        dynamic reader = connection.Query<dynamic>("UserResourceGet", new { UserId = UserId }, commandType: CommandType.StoredProcedure).SingleOrDefault();
        resource.Wood.value = reader.Wood;
        resource.Wood.increase = reader.WoodIncome;

        resource.Food.value = reader.Food;
        resource.Food.increase = reader.FoodIncome;

        resource.Stone.value = reader.Stone;
        resource.Stone.increase = reader.StoneIncome;

        resource.Gold.value = reader.Gold;
        resource.Gold.increase = reader.GoldIncome;
    }
    return resource;

SQL SP >

SELECT  Wood, Food, Stone, Gold, WoodIncome, FoodIncome, StoneIncome, GoldIncome
FROM Resources WHERE UserId = @UserId

クラス >

public class Resource
{
    public int Wood { get; set; }
    public int Food { get; set; }
    public int Stone { get; set; }
    public int Gold { get; set; }
}

public class ResourceIncrease
{
    public Increase Wood{ get; set; }
    public Increase Food { get; set; }
    public Increase Stone { get; set; }
    public Increase Gold { get; set; }

    public ResourceIncrease()
    {
        this.Wood = new Increase();
        this.Food = new Increase();
        this.Stone = new Increase();
        this.Gold = new Increase();
    }
}

public class Increase
{
    public int value { get; set; }
    public int increase { get; set; }
}
4

1 に答える 1