我有問題得到一個「CodeFluent.Runtime.CodeFluentDuplicateException」,我可能缺少一些基本的東西。CodeFluentDuplicateException我失去了什麼
但是,我首先關注了使用ServiceStack和codefluents的博客,並製作了我自己的template。 我沒有問題得到實體,但做了一個讓我提到一個例外。
好吧,也許我在我的模板中做了一些錯誤,所以我採取另一種方法尋找答案,我找到了一個使用Webapi和模板的「完整」項目,隨時可以使用。 Generate ASP .NET Web API Controllers using Templates。
這生成所有的控制器,似乎工作。但是,當使用「put」時,我有相同的豁免。
這是生成控制器代碼的一個例子爲將
public HttpResponseMessage Put([FromBody]Country value)
{
if (value == null || !value.Save())
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
return Request.CreateResponse(HttpStatusCode.OK, value);
}
這是我如何使用控制器上方的Xamarin.Forms溶液內。
public async Task UpdateAsync(Country update, bool isNewItem=false)
{
HttpClient client = new HttpClient();
// RestUrl = http://developer.xamarin.com:8081/api/todoitems{0}
var uri = new Uri(string.Format(Constants.RestUrl2, update.Id));
try
{
var json = JsonConvert.SerializeObject(update);
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = null;
if (isNewItem)
{
response = await client.PostAsync(uri, content);
}
else
{
response = await client.PutAsync(uri, content);
}
if (response.IsSuccessStatusCode)
{
Debug.WriteLine(@" TodoItem successfully saved.");
}
}
catch (Exception ex)
{
Debug.WriteLine(@" ERROR {0}", ex.Message);
}
}
有什麼建議我缺少什麼?
感謝所有幫助 //格雷格