首先踩堆栈溢出,我会尽力做到最好..
下面,我的模型来自 ADO.NET(mysql 数据库)
http://img585.imageshack.us/img585/4533/screenshot20120519at143.png
// CHECK USER+PASS
rmEntities2 myDb = new rmEntities2();
var query = from c in myDb.users
where c.use_login == run.name
where c.use_password == run.pass
select c.use_id;
if (query.Count() == 0)
{
return "ERROR USER/PASSWORD";
}
else
{
// Linq insert DB
running newRun = new running();
newRun.run_start_time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0)
.AddSeconds(Double.Parse(run.start));
newRun.run_end_time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0)
.AddSeconds(Double.Parse(run.stop));
newRun.run_distance = (float)run.distance;
newRun.run_nbfootsteps = run.nbfootsteps;
newRun.run_vo2max = run.vo2Max;
foreach (int u in query)
{
newRun.user.use_id = u;
}
myDb.AddTorunnings(newRun);
myDb.SaveChanges();
return "RUNNING ADDED";
}
问题出在这一行:
newRun.user.use_id = u;
我想在我的运行表中设置用户的 run_use_id。
什么是最好的方法?