I want to join between two tables and display the result in the view. Could you tell me how? How to submit by viewbag?
Table 1.
namespace ControleTTM.EntityFramework
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
using System.Web.Mvc;
[Table("CONTROLETTM.NEW_CTTM_TICKETS_OPEN")]
public partial class NEW_CTTM_TICKETS_OPEN
{
[Key]
[Column(Order = 0)]
public decimal CTTM_CHAMADO_ID { get; set; }
//[Key]
//[Column(Order = 1)]
public decimal SYSTEM_STATUS_ID { get; set; }
[Key]
[Column(Order = 1)]
public decimal ID_SISTEMA_ORIGEM { get; set; }
[Key]
[Column(Order = 2)]
[StringLength(30)]
public string CODIGO { get; set; }
public decimal? IDADE { get; set; }
public decimal? IDADE_CASO { get; set; }
public decimal? TELEFONE_PRINCIPAL { get; set; }
public decimal? ID_ORIGIN { get; set; }
public DateTime? DT_CRIACAO { get; set; }
[StringLength(255)]
public string STATUS { get; set; }
[StringLength(255)]
public string SEVERIDADE { get; set; }
[StringLength(255)]
public string RAZAO_SOCIAL { get; set; }
[StringLength(255)]
public string SEGMENTO { get; set; }
[StringLength(255)]
public string ORGANIZACAO { get; set; }
public decimal? ID_TITLE { get; set; }
[StringLength(255)]
public string PLANO { get; set; }
public decimal? TELEFONE_ALTERNATIVO { get; set; }
public decimal? CPF { get; set; }
public decimal? CNPJ { get; set; }
public string HISTORICO { get; set; }
public string NOTAS { get; set; }
[StringLength(255)]
public string NE_ID { get; set; }
public decimal? ORIGIN_LEVEL { get; set; }
public decimal? ID_SLA { get; set; }
public decimal? SLA_LEVEL { get; set; }
public decimal? ID_TYPE { get; set; }
public decimal? PENDING { get; set; }
public decimal? FG_TRATAMENTO { get; set; }
public decimal? ID_USER { get; set; }
public DateTime? DT_IMPORT { get; set; }
public DateTime? DT_QUEUE_ENTRY { get; set; }
}
}
Table 2
namespace ControleTTM.EntityFramework
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
using System.Web.Mvc;
[Table("CONTROLETTM.NEW_CTTM_ORIGIN_PRIORITY")]
public partial class NEW_CTTM_ORIGIN_PRIORITY
{
[Key]
public decimal ID_ORIGIN { get; set; }
[Required]
[StringLength(50)]
public string DESC_ORIGIN { get; set; }
public decimal ORIGIN_LEVEL { get; set; }
}
}
Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;
using System.Net;
using ControleTTM.EntityFramework;
using ControleTTM.Models;
using ControleTTM.Helper;
using ControleTTM.ViewModel;
using ControleTTM.Filters;
namespace ControleTTM.Controllers
{
[MyFirstCustomFilter]
public class ChamadoController : Controller
{
private ModelCTTM db = new ModelCTTM();
Teste2ViewModel model = new Teste2ViewModel();
// GET: Chamado
public ActionResult Index()
{
var resultado = (from a in db.NEW_CTTM_TICKETS_OPEN
join b in db.NEW_CTTM_ORIGIN_PRIORITY
on a.ID_ORIGIN equals b.ID_ORIGIN
select new
{
CTTM_CHAMADO_ID = a.CTTM_CHAMADO_ID,
SYSTEM_STATUS_ID = a.SYSTEM_STATUS_ID,
ID_SISTEMA_ORIGEM = a.ID_SISTEMA_ORIGEM,
CODIGO = a.CODIGO,
IDADE = a.IDADE,
IDADE_CASO = a.IDADE_CASO,
TELEFONE_PRINCIPAL = a.TELEFONE_PRINCIPAL,
ID_ORIGIN = a.ID_ORIGIN,
DT_CRIACAO = a.DT_CRIACAO,
STATUS = a.STATUS,
SEVERIDADE = a.SEVERIDADE,
RAZAO_SOCIAL = a.RAZAO_SOCIAL,
SEGMENTO = a.SEGMENTO,
ORGANIZACAO = a.ORGANIZACAO,
ID_TITLE = a.ID_TITLE,
PLANO = a.PLANO,
TELEFONE_ALTERNATIVO = a.TELEFONE_ALTERNATIVO,
CPF = a.CPF,
CNPJ = a.CNPJ,
HISTORICO = a.HISTORICO,
NOTAS = a.NOTAS,
NE_ID = a.NE_ID,
ORIGIN_LEVEL = a.ORIGIN_LEVEL,
ID_SLA = a.ID_SLA,
SLA_LEVEL = a.SLA_LEVEL,
ID_TYPE = a.ID_TYPE,
PENDING = a.PENDING,
FG_TRATAMENTO = a.FG_TRATAMENTO,
DESC_ORIGIN = b.DESC_ORIGIN
}).ToList();
ViewBag.TipoEvento = resultado;
return View();
}
}
}
view model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.Entity;
using System.Net;
using ControleTTM.EntityFramework;
using ControleTTM.Models;
using ControleTTM.Helper;
using ControleTTM.ViewModel;
using ControleTTM.Filters;
using System.ComponentModel.DataAnnotations.Schema;
namespace ControleTTM.ViewModel
{
public class Teste2ViewModel
{
public IEnumerable<NEW_CTTM_TICKETS_OPEN> chamado { get; set; }
public IEnumerable<NEW_CTTM_ORIGIN_PRIORITY> OriginPriority { get; set; }
}
}