I want to access the data of table using WCF services.
My code is like:
The table name is marital_status and have relations with other tables.
[OperationContract]
marital_status[] GetMartialStatus();
public marital_status[] GetMartialStatus()
{
using (HREntities context = new HREntities())
{
marital_status[] obj = context.marital_status.ToArray();
return obj;
}
}
When i try to use this:
List<marital_status> asd = EntityService.ServiceInstance.GetMartialStatus().ToList();
I got the error that context is no longer available.
I am using array then there should not be any problem.
PLEASE NOTE: I dont want to create DATA CONTRACTS etc. Because Linq to Entities already expose the classes for the tables.
Any help is appreciated
UPDATE:
If i explicitly remove LAZY LOADING = false in the code my code starts working. But i do not want to remove this
Are there any relations between marital_status and other entities?
Maybe you should include them in the result or explicitly load them?
or
If you modify data, you may also want to try
context.marital_status.MergeOption(MergeOption.NoTracking);Btw, your method is named Martial and relation is Marital 😉