Accessing a DAL Service that returns a List [Resolved]

Posted by Vuyiswamb under WCF on 2/3/2011 | Points: 10 | Views : 2746 | Status : [Member] [MVP] [Administrator] | Replies : 6
I have a Service that is a Data-layer , this Service is being called by another service that is a Business layer, The first later is working fine.
Now i want to access the function in the Data-layer, i can access the Function.Now my Challenge is here.

The function in a Data-layer Returns

[code]
public List<LoginModel> GetLogins()
{

} [/code]

so that means the "LoginModel" is the Class that is my Model and and now in my Business logic layer , i am accessing the Data-layer service like this

[/code]
public List&lt;DalService.LoginModel&gt; GetLogins()
{
DalService.DALClient obj = new DalService.DALClient();

List&lt;DalService.LoginModel&gt; m_logins = new List&lt;DalService.LoginModel&gt;();

m_logins = obj.GetLogins();

return m_logins;
} [code]

now the problem here is this line



[code] m_logins = obj.GetLogins();[/code]


[code] Error 1 Cannot implicitly convert type 'BLLBusiness.DalService.LoginModel[]' to 'System.Collections.Generic.List&lt;BLLBusiness.DalService.LoginModel&gt;' C:\WorkDevelopment\Silver\BLLBusiness\BLLBusiness\cBLLService.cs 28 24 BLLBusiness [/code]


Thanks

Thank you for posting at Dotnetfunda
[Administrator]



Responses

Posted by: Sathya4260 on: 2/3/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
ur error at

DalService.DALClient objDatalayer = new DalService.DALClient();

use generic class for List<DalService.DALClient> class to return objects in the generic list form.


Sathish Kumar S

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

Posted by: Karthikanbarasan on: 2/3/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Try using a generic type using Generics to get the return object and then you can use it as per ur requirement.

Thanks
Karthik
www.f5Debug.net

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

Posted by: Sathya4260 on: 2/3/2011 [Member] Starter | Points: 25

Up
0
Down
hi,

Check whether the obj m_logins is retured in the form of generic list,
both of them should be in the generic class list type..

public List<DalService.LoginModel> GetLogins()
{
DalService.DALClient obj = new DalService.DALClient();

List<DalService.LoginModel> m_logins = new List<DalService.LoginModel>();

m_logins = obj.GetLogins();

return m_logins;
}

or change the method to just return the objects...

public List<LoginModel> GetLogins()
{
}



Sathish Kumar S

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

Posted by: Vuyiswamb on: 2/3/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
i am not sure what you mean because i have this


public List<LoginModel> GetLogins()
{
DalService.DALClient objDatalayer = new DalService.DALClient();

List<LoginModel> m_logindetails = new List<LoginModel>();

m_logindetails = objDatalayer.GetLogins();

return m_logindetails;

}


and the Error is

             m_logindetails = objDatalayer.GetLogins(); 


and my function on the DataLayer service looks like this


public List<LoginModel> GetLogins()
{
SqlConnection con = new SqlConnection("User id=sa;Password=tdhskseraaeqw;Server=devsql1;Database=Mydb");

SqlCommand cmdselect = new SqlCommand("usp_Records");

cmdselect.CommandType = CommandType.StoredProcedure;

SqlDataAdapter da = new SqlDataAdapter();

cmdselect.Connection = con;

da.SelectCommand = cmdselect;


DataTable dt = new DataTable();

List<LoginModel> m_Logins = new List<LoginModel>();

try
{
con.Open();

da.Fill(dt);

m_Logins = convertDatatableToList(dt);
}
catch (SqlException ex)
{
throw ex;
}
finally
{
con.Close();
}
return m_Logins;

}

Thanks


Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: Karthikanbarasan on: 2/3/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi Vuyiswamb,

You need to use the Generic type to get the return object since you dnt have the initialized object...

Thanks
Karthik
www.f5Debug.net

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

Posted by: Vuyiswamb on: 2/3/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Good Day Guys,

Thanks for your help


Thank you for posting at Dotnetfunda
[Administrator]

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

Login to post response