3
Reply

Help with query

samuel ferreira

samuel ferreira

Oct 3 2013 12:19 PM
869

Hello!

I have a database with this structure:

OCORRENCIAS:

  • OCORRENCIA_ID
  • DEPARTAMENTO_ID
  • STATUS_ID
  • DATA_CRIACAO

DEPARTAMENTOS:

  • DEPARTAMENTO_ID
  • NOME

STATUS:

  • STATUS_ID
  • NOME

USUARIOS

  • USUARIO_ID
  • NOME

USUARIO_DEPARTAMENTO

  • USUARIO_ID
  • DEPARTAMENTO_ID


The Entity data model, in the Entity Departamento have a navigation property USUARIOS  and in the table USUARIOS, a navigation property DEPARTAMENTOS.

I need to get only the records for the departments that the user is connected.

How can I do this?

This is my query.

var users = db.USUARIOS.FirstOfDefault();

var ocorrencias= (from r in db.OCORRENCIAS join d in db.DEPARTAMENTOS on r.DEPARTAMENTO_ID equals d.DEPARTAMENTO_ID join s in db.STATUS on r.STATUS_ID equals s.STATUS_ID select new { id = r.OCORRENCIA_ID, departamento = d, status = s.NOME, data = r.DATA_CRIACAO }) .AsEnumerable();


Can someone help me?


Answers (3)