I have this class:
public class MontaArvoreAcao
{
public int IDRuptura { get; set; }
public DateTime DataRuptura { get; set; }
public int IDMotivo { get; set; }
public string Motivo { get; set; }
public int IDOrigem { get; set; }
public string CodigoPDV { get; set; }
public string UF { get; set; }
public string Cidade { get; set; }
public string Cnpj { get; set; }
public string Descricao { get; set; }
public string Codigo_Apresentacao { get; set; }
public string Unidade_Negocio { get; set; }
public string Franquia { get; set; }
public string Familia { get; set; }
public string Descricao { get; set; }
}
The purpose of this class is for me to have a Model that I can pick up from my view and work with it there. This class (Model) will be fed with this code in the controller:
[HttpPost]
public JsonResult ArvoreAcao(string _uf)
{
RupturaEntities db = new RupturaEntities();
var monta_arvore = (from rup in db.Ruptura
from apr in db.Apresentacao.Where(apr => apr.Codigo_Apresentacao == rup.Codigo_Apresentacao)
from pdv in db.PDV.Where(pdv => pdv.CodigoPDV == rup.CodigoPDV)
from mot in db.Motivo.Where(mot => mot.IDMotivo == rup.IDMotivo)
select new {
rup.IDRuptura,
rup.DataRuptura,
rup.IDMotivo,
mot.Motivo1,
rup.IDOrigem,
rup.CodigoPDV,
pdv.UF,
pdv.Cidade,
loja = pdv.Cnpj + " - " + pdv.Descricao,
rup.Codigo_Apresentacao,
apr.Unidade_Negocio,
apr.Franquia,
apr.Familia,
apr.Descricao}).ToList().Distinct().OrderBy(apr => apr.Descricao);
ViewBag.result_arvore = monta_arvore;
return Json(new { monta_arvore}, JsonRequestBehavior.AllowGet);
}
The question is: How do I get this Model in the View with all values coming from linq above, ie from the database? One more question: All IDs of this class are Foreign Key. Is it correct how to represent a Foreign Key as it is in the class or do I have to do an ICollection?