Data from the same table for different Views?

0

I have found it difficult to solve the following problem: Assuming I have the following structure in the database:

Id              int identity primary key
CodigoBanco     char(3)
Descricao       varchar(100)
Endereco        varchar(300)
Bairro          varchar(100)
CodCidade       int 
Numero          varchar(10)
Complemento     varchar(15)
DataInclusao    datetime
DataAlteracao   datetime
UsrAlteracao    int 
Observacao      varchar(3000)

However, the system has 3 views:

View1 - You need the Id and Description fields to populate a dropdownlist;

View2 - You need the Id fields, Bank Code, Description, Address, Neighborhood, CodCity, Number

View3 - Need all fields;

With the Entity Framework, my approach has been to return an IQueryable from the repository and make the Select on the Controller as needed.

But this is not possible when we are using Procedure + ADO.NET (Not by my will).

What would be the best approach?

Create a procedure and a class for each situation?

Create a procedure for each situation using the same class (even if partial filling of properties)?

Disregard data traffic and always bring all columns, and thus only developing a procedure?

    
asked by anonymous 25.10.2018 / 03:59

1 answer

0

If data traffic between the application server and the database is not a critical issue. What can be done is to create a ViewModel for each view in order to reduce data traffic between the server and the client.

Creating a procedure for each query would be most efficient in resource saving and performance enhancement ... but this will increase complexity and generate more work on maintenance.

  

View1 - You need the Id and Description fields to populate a   dropdownlist;

public DropDownViewModel
{
   public int Id {get; set;}
   public string Descricao {get; set;}
}
  

View2 - Need the Id fields, Bank Code, Description, Address,   Neighborhood, CodCity, Number

public CardViewModel {
   public int Id {get; set;}
   public string CodigoBanco {get; set;}
   public string Descricao {get; set;}
   public string Endereco {get; set;}
   public string Bairro {get; set;}
   public int CodCidade {get; set;}   
   public string Numero {get; set;}
}
  

View3 - Need all fields;

public DetalheViewModel 
{
   public int Id {get; set;}
   public string CodigoBanco {get; set;}
   public string Descricao {get; set;}
   public string Endereco {get; set;}
   public string Bairro {get; set;}
   public int CodCidade {get; set;}   
   public string Numero {get; set;}
   public string Complemento  {get; set;} 
   public DateTime DataInclusao {get; set;}
   public DateTime DataAlteracao {get; set;}
   public int UsrAlteracao {get; set;}
   public string Observacao  {get; set;}
}
    
25.10.2018 / 22:26