function to Fetch Generic Collections

Posts   
 
    
rikas
User
Posts: 2
Joined: 30-Jan-2009
# Posted on: 30-Jan-2009 18:26:23   

Im trying to create a function that will fetch an entire collection using WCF 3.0 The trick behind this function is that is supposed the work with any Collection of Entities that i pass as parameter.

This is how far i got:

    public EntityCollection<TEntity> FetchEntityCollection<TEntity>()
    where TEntity : EntityBase2, IEntity2
    {
        EntityCollection<TEntity> _collection = new EntityCollection<TEntity>();

        using (DataAccessAdapter _adapter = new DataAccessAdapter())
            _adapter.FetchEntityCollection(_collection, null, 0, null);

        return _collection;
    }

Now this works fine if not used with WCF 3.0. It gives me an error that cant serialize generic Entities.

Please help

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jan-2009 19:43:32   

Could you please post the exception details (ex message and stack trace)? and the LLBLGen Pro build and Runtime Libraries version as well. This way we can help you better wink (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7725)

David Elizondo | LLBLGen Support Team
rikas
User
Posts: 2
Joined: 30-Jan-2009
# Posted on: 30-Jan-2009 19:45:34   

System.Runtime.Serialization.InvalidDataContractException was unhandled Message="Type 'SciennaDB.HelperClasses.EntityCollection1[TEntity]' cannot be exported as a schema type because it is an open generic type. You can only export a generic type if all its generic parameter types are actual types." Source="System.Runtime.Serialization" StackTrace: at System.Runtime.Serialization.DataContractSet.EnsureTypeNotGeneric(Type type) at System.Runtime.Serialization.XsdDataContractExporter.GetSchemaTypeName(Type type) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.ValidateDataContractType(Type type) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.CreatePartInfo(MessagePartDescription part, OperationFormatStyle style, DataContractSerializerOperationBehavior serializerFactory) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.CreateMessageInfo( DataContractFormatAttribute dataContractFormatAttribute, MessageDescription messageDescription, DataContractSerializerOperationBehavior serializerFactory) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter..ctor(OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory) at System.ServiceModel.Description.DataContractSerializerOperationBehavior.GetFormatter(OperationDescription operation, Boolean& formatRequest, Boolean& formatReply, Boolean isProxy) at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description. IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy) at System.ServiceModel.Description.DispatcherBuilder.BindOperations(ContractDescription contract, ClientRuntime proxy, DispatchRuntime dispatch) at System.ServiceModel.Description.DispatcherBuilder.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime) at System.ServiceModel.Description.DispatcherBuilder.BuildProxyBehavior(ServiceEndpoint serviceEndpoint, BindingParameterCollection& parameters) at System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint) at System.ServiceModel.ChannelFactory.CreateFactory() at System.ServiceModel.ChannelFactory.OnOpening() at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.ChannelFactory.EnsureOpened() at System.ServiceModel.ChannelFactory1.CreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.ChannelFactory`1.CreateChannel() at Scienna.DesignerStudio.MainForm..ctor() in C:\Scienna\DesignerHost\MainForm.cs:line 117 at Scienna.DesignerStudio.MainForm.Main() in C:\Scienna\DesignerHost\MainForm.cs:line 960 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Feb-2009 23:24:54   

Hi there,

Generics aren't supported in webservices nor are polymorphic fetches using single entity instances. This means that the type returned by the webmethod is the type of object you will get on the client. Please take a look a the docs. So, you should use EntityCollection class (non generic).

David Elizondo | LLBLGen Support Team