1
I have the following code snippet:
var filter = new { categoria = 1, cond2 = foo, ... };
p = new ProdutoBusiness().listarProdutos( filter ).ToList();
I wanted to work with this anonymous type as a filter parameter, but I don’t know how to receive this type of value in the reference method:
public IEnumerable<Produto> listarProdutos( tipo???? filter = null) {
My intention is to change the query according to what comes in the filter. For example:
if(filter != null){
if(filter.categoria != ""){
query = from P in con.produto
join C in con.categoria on P.categoriaID equals C.categoriaID
where P.ativo == true
&& P.categoriaID == filter.categoria
orderby P.nome ascending
select P;
}
[...]
}
Any ideas/suggestions?
/*************/
If anyone has the same question with these guys 'Dynamic', mentioned in the reply, I resolved so:
Popular the object:
var filter = new { categoria = 1, cond2 = foo, ... }
Receiving the parameter:
public IEnumerable<Produto> listarProdutos( dynamic filter = null) {}
Getting the key value':
var fCategoria = filter.GetType( ).GetProperty( "categoria" ).GetValue( filter, null );
Anonymous type is impossible. You can use
dynamic
, but possibly, there are several better solutions than that. What’s the problem of creating a type for this?– Jéf Bueno