私は MVC C# とエンティティ フレーム ワークを使用しています。
したがって、私の部分的なビューでは、データを変更したいと考えています。
これは私のコントローラーです
public ActionResult BusinessDetails(){
int bsId = bskey ?? default(int);
var BusinessQuery = GetBusinessById(bsId);
var PeopleQuery = BusinessQuery.t_PEOPLE
.Where(p => p.PP_IS_CONTACT == true).AsEnumerable();
var peopleCollection = new EntityCollection<t_PEOPLE>();
foreach (var m in PeopleQuery)
{
//This is problem.-----------
peopleCollection.Add(m);
} //--------------
BusinessQuery.t_PEOPLE = peopleCollection;
return PartialView("_EditBusiness", BusinessQuery);
}
return RedirectToAction("Index");
}
public t_BUSINESS GetBusinessById(int id){
if (id == 0)
return null;
var query = from b in db.t_BUSINESS
where b.BS_KEY == id
select b;
var Business = query.FirstOrDefault();
return Business;
}
PeopleQuery
では、どうすれば を自分の に割り当てることができますかBusinessQuery.t_PEOPLE
。
エラーがあり、言う
The object could not be added to the EntityCollection or EntityReference. An object that is attached to an ObjectContext cannot be added to an EntityCollection or EntityReference that is not associated with a source object