How to find a List using Find method of entity framework passing Array as parameter? c# entity-framework entity-framework-6 find

Question

I'd like to learn where to look for aList<Object> utilizing the Find function while supplying an Array(object[] (as a parameter)

I want to use the Primary Key to find all the data.

I first compile a list of all the PK I intend to utilize as a guide:

List<int> lCodigoServicos = new List<int>();
foreach (ServicosSelecionadosModelView servicoSelecionado in lServicos.FindAll(s => !string.IsNullOrEmpty(s.selecionado) && s.selecionado.ToLower() == "on" ))
         lCodigoServicos.Add(servicoSelecionado.servico.SerId);

I try to find all data by PK after filling out my list of PKs.

var lServicosInformados = db.Servicos.Find(lCodigoServicos.ToArray());

I attempt this, but I receive the following error:

The specified parameter type 'System.Int32[]' is not valid. Only scalar types, such as System.Int32, System.Decimal, System.DateTime, and System.Guid, are supported.

Please explain to us how to do it correctly. Thanks.

As stated below, the appropriate response is:

var lServicosInformados = db.Servicos.Where(x => lCodigoServicos.Contains(x.PKId)); 
1
1
5/18/2015 1:45:10 PM

Accepted Answer

ZZZ_tmp
5
5/18/2015 1:31:54 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow