Data from the same table for different views?

Asked

Viewed 37 times

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 fill in a dropdownlist;

View2 - You need the fields Id, Codigobanco, Descricao, Endereco, Bairro, Codcidade, Numero;

View3 - Needs all the fields;

With the Entity Framework, my approach has been to return a Iqueryable from the repository and make the Select in 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 precedent and a class for each situation?

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

Disregard the data traffic and always bring all the columns, and so, developing only a Procedure?

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 server and client.

Creating a precedent for each query would be the most resource-efficient and performance-enhancing... but this will increase complexity and generate more maintenance work.

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

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

View2 - You need the fields Id, Codigobanco, Descricao, Endereco, Neighborhood, Codcidade, Numero;

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 - Needs 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;}
}

Browser other questions tagged

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