Query using Object with Entity Framework

Asked

Viewed 57 times

1

I have a method that gets one object which may be both int as string, someone knows a way to do the entity framework interpret the Object!?

I know I can make one if and do the verification, but I’m trying to do it in a simpler way because I will use it in various places of code.

Below is an example of the code:

public JsonResult LoadForm(object id)
{
     if ((form = db.tbSystFormulario.FirstOrDefault(f => f.pk_id.CompareTo(id) == 0)) == null)
     {
          form = db.tbSystFormularioCampo.FirstOrDefault(f => f.tx_nome.CompareTo(id) == 0);
     }

     return Json(LoadForm(form), JsonRequestBehavior.AllowGet);
}
  • I don’t understand it well. If you want to make a query by the primary key, use db.tbSystFormulario.Find(id)..

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.