Cannot implicitly convert type to 'System.Collections.Generic.IEnumerable<T>'. An explicit conversi

Posted by Manorama under WCF on 9/6/2013 | Points: 10 | Views : 4671 | Status : [Member] | Replies : 2
I am using WCF service .here I am implemented IEnumerable method like this

IEnumerable<ITDeclarationDetails> IHRService.GetITDeclarationDetails(long EmpID)
{
ITDeclarationDetails itdetails = new ITDeclarationDetails();
IEnumerable<ITDeclarationDetails> ITDeclarationDetails = (from ITdeclaraion in dbEntities.GetITDeclarationDetails(EmpID)
select new ITDeclarationDetails
{
EmpID = ITdeclaraion.EmpID,
Particulars1 = ITdeclaraion.Particulars,
MonthlyAmount = ITdeclaraion.MonthlyAmount,
NoofMonths = ITdeclaraion.NoofMonths,
AnnualAmnt = ITdeclaraion.AnnualAmnt,
ID = ITdeclaraion.ID
});
foreach (var item in ITDeclarationDetails)
{

if (item.ID == 1)
{
itdetails.MARentPaidByEmp = item.MonthlyAmount;
itdetails.NMRentPaidByEmp = item.NoofMonths;
itdetails.AARentPaidByEmp = item.AnnualAmnt;
}
if (item.ID == 2)
{
itdetails.MALifeInsPrem = item.MonthlyAmount;
itdetails.NMLifeInsPrem = item.NoofMonths;
itdetails.AALifeInsPrem = item.AnnualAmnt;
}
}
return itdetails ;
how to return this itdetails ,
Please help me urgent requirement.
Thanks & Regards ,
Manorama

ManoRama


Responses

Posted by: Bandi on: 9/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this link
http://forums.asp.net/t/1265711.aspx

I think at the end this you should convert result set to specific type
IEnumerable<ITDeclarationDetails> IHRService.GetITDeclarationDetails(long EmpID)
{
ITDeclarationDetails itdetails = new ITDeclarationDetails();
IEnumerable<ITDeclarationDetails> ITDeclarationDetails = (from ITdeclaraion in dbEntities.GetITDeclarationDetails(EmpID)
select new ITDeclarationDetails
{
EmpID = ITdeclaraion.EmpID,
Particulars1 = ITdeclaraion.Particulars,
MonthlyAmount = ITdeclaraion.MonthlyAmount,
NoofMonths = ITdeclaraion.NoofMonths,
AnnualAmnt = ITdeclaraion.AnnualAmnt,
ID = ITdeclaraion.ID
}).ToList() ;

http://stackoverflow.com/questions/4256329/cannot-implicitly-convert-type-system-collections-generic-ienumerableanonymous

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Manorama, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 9/6/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

You can just try in this way:

List<ITDeclarationDetails> objITDeclarationDetails = (from ITdeclaraion in dbEntities.GetITDeclarationDetails(EmpID)
select new ITDeclarationDetails
{
EmpID = ITdeclaraion.EmpID,
Particulars1 = ITdeclaraion.Particulars,
MonthlyAmount = ITdeclaraion.MonthlyAmount,
NoofMonths = ITdeclaraion.NoofMonths,
AnnualAmnt = ITdeclaraion.AnnualAmnt,
ID = ITdeclaraion.ID
}).ToList<ITDeclarationDetails>();

Thank you.

Thank you,
Govind

Manorama, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response