我正在尝试使用Entity Framework将数据插入到没有主键的数据库表中。
发生错误
您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在'(SELECT \ n collection.CustomerID,collection.AmountRecevied,\ n'第1行)附近使用正确的语法
我使用fiddler发布了数据,
{"CustomerID":"12122","AmountRecevied":"2000","Date_Time":"","longitude":"17.3660° N","AgentID":"15","Money_Receipt_No":"56654","Payment_Mode":"cash","Money_Receipt_Photo":"","latitude":"78.4760° E"}
代码:
try
{
var vvv = cs.collections.Select(x => x.CustomerID).ToList();
cs.collections.Add(collection);
cs.SaveChanges();
}
catch
{
return false;
}
return true;
[HttpPost]
public HttpResponseMessage PostUser(collection Collection)
{
if (Collection == null)
return Request.CreateResponse(HttpStatusCode.BadRequest, "not created");
if (obj.PostUser(Collection))
{
return Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.create(Collection));
}
else
return Request.CreateResponse(HttpStatusCode.BadRequest, "Could not save to the database");
}
属性
public partial class collection
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string CustomerID { get; set; }
public decimal AmountRecevied { get; set; }
public Nullable<System.DateTime> Date_Time { get; set; }
public string longitude { get; set; }
public Nullable<int> AgentID { get; set; }
public Nullable<int> Money_Receipt_No { get; set; }
public string Payment_Mode { get; set; }
public byte[] Money_Receipt_Photo { get; set; }
public string latitude { get; set; }
}