0
I’m trying to create a table with Union, I made a class to popular on ViewModel
, in this way:
public class ListVencimentos {
public int Id { get; set; }
public DateTime Data { get; set; }
public int? TipoDocumentoId { get; set; }
public Models.TipoDocumento TipoDocumento { get; set; }
public float Valor { get; set; }
public float JaPago { get; set; }
public float Saldo { get; set; }
public float Desconto { get; set; }
public float Mora { get; set; }
public float Multa { get; set; }
public float Outros { get; set; }
public float Total { get; set; }
public DateTime? DataPagamento { get; set; }
public int? DiasAtraso { get; set; }
}
Calling it that public IEnumerable<ListVencimentos> ListVencimentos { get; set; }
And to make the selects
got like this, that’s pulling properly:
var un = db.ContasPagar.Include(c => c.ContasPagarP).Where(c => c.FornecedorId == id).Select(c => new
{
Id = c.Id,
Data = c.Data,
TipoDocumentoId = c.TipoDocumentoId,
Valor = c.Valor,
JaPago = c.JaPago,
Saldo = c.Saldo,
Desconto = c.Desconto,
Mora = c.Mora,
Multa = c.Multa,
Outros = c.Outros,
Total = c.Total,
DataPagamento = c.DataPagamento,
DiasAtraso = c.DiasAtraso
}).ToList()
.Union(db.FaturaContasPagar.Include(r => r.FaturaContasPagarP).Where(r => r.FornecedorId == id).Select(r => new
{
Id = r.Id,
Data = r.Data,
TipoDocumentoId = r.TipoDocumentoId,
Valor = r.Valor,
JaPago = r.JaPago,
Saldo = r.Saldo,
Desconto = r.Desconto,
Mora = r.Mora,
Multa = r.Multa,
Outros = r.Outros,
Total = r.Total,
DataPagamento = r.DataPagamento,
DiasAtraso = r.DiasAtraso
}).ToList());
Only when I go popular the ListVencimentos
, he is returning me the following error.
It is not possible to implicitly convert "System.Collections.Generic.Ienumerable<>" to "System.Collections.Generic.Ienumerable". There is an explicit conversion (there is an absent conversion?)
How can I do, am I forgetting some detail ?
EDIT
I’m trying to fill in this way:
ListVencimentos = un.Select(r => new ListVencimentos { r.Id, r.Data, r.TipoDocumentoId, r.Valor, r.JaPago, r.Saldo, r.Desconto,
r.Mora, r.Multa, r.Outros, r.Total, r.DataPagamento })
And he’s returning the error:
It is not possible to initialize type "Stripes" with a collection initializer because it does not implement "System.Collections.Ienumerable"
How can I load the result un
, in a table
? Every way I try it returns some kind of conversion error.
Change from anonymous type to your type in your
.Select(s => new ListVencimentos { ... })
– Pedro Paulo
He returned to me the following mistake. Unable to initialize type "Stripes" with a collection initializer because it does not implement "System.Collections.Ienumerable" I switched to
ListVencimentos = un.Select(r => new ListVencimentos { r.Id, r.Data, r.TipoDocumentoId, r.Valor, r.JaPago, r.Saldo, r.Desconto,
 r.Mora, r.Multa, r.Outros, r.Total, r.DataPagamento })
– Mariana
Are you trying to initialize your class as a list? Example:
ListVencimentos lista = un.Select(s => new ListVencimentos {...});
If so, it won’t work because your class is not a collection.– Pedro Paulo
@Pedropaulo yes, na
ViewModel
I declared sopublic IEnumerable<ListVencimentos> ListVencimentos { get; set; }
and in theload
of editing is like this:ListVencimentos= un.Select(r => new ListVencimentos { r.Id, r.Data, r.TipoDocumentoId, r.Valor, r.JaPago, r.Saldo, r.Desconto,
 r.Mora, r.Multa, r.Outros, r.Total, r.DataPagamento }),
– Mariana
So in my head without analyzing the code as a whole, it gets a little complicated, I’d have to do a better analysis, because apparently that’s what it would be... Will end up generating Flood in comments, if you want to share the discussion calls in chat.
– Pedro Paulo