我正在创建简单的应用程序,这有助于组织我的口味混合自己的电子液体。我在localDb中有三个表:
ID,姓名,公司,商店,金额
ID,姓名,日期
Id,FlavourId,RecipeId,PercentageAmount
我也提供了模特:
public int Id { get; set; }
public string Name { get; set; }
public string Company { get; set; }
public string Shop { get; set; }
public double? Amount { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
public int Id { get; set; }
public Dictionary<Flavour, double?> RecipeElements { get; set; }
public int Id { get; set; }
public Flavour Flavour { get; set; }
public double? PercentageAmount { get; set; }
我执行查询以从数据库中获取所有食谱:
public IEnumerable<Recipe> GetAll(){
string sqlQuery = @"SELECT f.*, r.*, rf.PercentageAmount FROM Recipe r INNER JOIN RecipeFlavours rf ON rf.RecipeId = r.Id INNER JOIN Flavour f ON rf.FlavourId = f.Id";
var lookup = new Dictionary<int, Recipe>();
Db.Query<Recipe, Flavour,ElementRecipe, Recipe>(sqlQuery, (r, f, rf) =>{
Recipe recipe;
if(!lookup.TryGetValue(r.Id,out recipe))
lookup.Add(r.Id, recipe = r);
if(r.RecipeElements == null)
recipe.RecipeElements = new Dictionary<Flavour, double?>();
recipe.RecipeElements.Add(f,rf.PercentageAmount);
return recipe;
},splitOn: "RecipeId, FlavourId, Id, Id, Id");
return lookup.Values.ToList();
}
执行查询时,我得到例外:
An unhandled exception of type 'System.ArgumentException' occurred in Dapper.dll
Additional information: When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id
我无法识别我做错了什么。我在这个网站上学习:http://jsm85.github.io/tutorial/2016/04/13/map-multi-join-sql-query-using-dapper/