Question

I have been experimenting with using PetaPoco for a small project I am working, and it has been awesome so far.

I have created some additional, non auto-generated partial classes to hold various computed values, as shown in my example below. I can't get these additional properties to be serialized into a WCF response, but all of the properties in the auto-generated stuff serializes just fine. I tried using [Serializable] and [DataContract] on these custom properties, but they break the WCF service altogether.

Any ideas?

public partial class Session
    {
        [ResultColumn]
        public int ConnectedUserCount
        {
            get
            {
                AssistedServiceDB db = new AssistedServiceDB();
                return db.ExecuteScalar<int>("SELECT Count(*) FROM Session_AssistedServiceUser WHERE IsConnected = 1");
            }
        }  
Was it helpful?

Solution

There are couple of things to look to get partial WCF DataContracts to work. First, if the other Session class is marked with the DataContract then this class would also need to be marked the same way. This is assuming the ResultSession class is also serializable and/or marked as DataContract. The other issue is WCF requires properties to, as a minimum, have private setters so the ConnectedUserCount property needs to be changed to have one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top