1 ضمیمه
مشکل serialaize کردن entity frame work
با سلام
من یک متد برای پاس دادن اطلاعات با فرمت json نوشتم.اما موقع پر کردن اطلاعات به آبجکت EF نمیتونه اطلاعات رو serialaize بکنه .
ضمیمه 139568
مطابق عکس اطلاعات رو نمیتونه نشون بده .
[HttpPost]
public ActionResult GetCity(int idCountry)
{
TravelEnterAdminTemplate.Models.LG.MyJsonResult myresult = new Models.LG.MyJsonResult();
try
{
List<City> citylist = new List<City>();
var citystable = db.Cities.Where(p => p.CountryId == idCountry).ToList();
if (citystable != null)
{
foreach (var city in citystable)
{
myresult.obj = citystable;
}
myresult.Result = true;
}
else
{
myresult.Result = false;
myresult.message = "داده ای یافت نشد";
}
}
catch (Exception e)
{
errorlog.Error("DeleteShopping", "157", e.Source.ToString(), e.Message);
myresult.Result = false;
myresult.message = "خطا در بارگذاری اطلاعات";
}
return Json(myresult, JsonRequestBehavior.AllowGet);
}
نقل قول: مشکل serialaize کردن entity frame work
نقل قول: مشکل serialaize کردن entity frame work
من کدم رو این شکلی تغییر دادم و مشکل به صورت مصنوعی فعلا مرتفع شد اما نه دلیل این مشکل رو میدونم و نه نحوه برطرف کردن اون رو .البته این رو هم بگم که من در یک پروژه گروهی کار میکنم و از subversion استفاده میکنیم . یکی از برنامه نویسها گفتند که EF اش رو آپدیت کرده . من فکر میکنم دلیل این مشکل همین باشه. چون تو اینترنت هم جستجو کردم چیزی پیدا نکردم.
[HttpPost]
public ActionResult GetCity(int idCountry)
{
TravelEnterAdminTemplate.Models.LG.MyJsonResult myresult = new Models.LG.MyJsonResult();
try
{
List<City> citylist = new List<City>();
var citystable = db.Cities.Where(p => p.CountryId == idCountry).ToList();
if (citystable != null)
{
foreach (var city in citystable)
{
City newcity = new City();
newcity.NameFA = city.NameFA;
newcity.NameEN = city.NameEN;
newcity.CountryId = city.CountryId;
newcity.Id = city.Id;
citylist.Add(newcity);
}
myresult.obj = citylist;
myresult.Result = true;
myresult.message = "found data.";
}
else
{
myresult.Result = false;
myresult.message = "داده ای یافت نشد";
}
}
catch (Exception e)
{
errorlog.Error("DeleteShopping", "157", e.Source.ToString(), e.Message);
myresult.Result = false;
myresult.message = "خطا در بارگذاری اطلاعات";
}
return Json(myresult, JsonRequestBehavior.AllowGet);
}