This project has moved. For the latest updates, please go here.
In a typical Web API that deals with business logic rather than only visual effects of AJAX, the POCO classes of domain models may have some members for Entity Framework only, like this one:

    [DataContract(Namespace = Constants.DataNamespace)]
    [Serializable]
    public class Entity : ITrackableEntity
    {
        public Entity()
        {
            Sections = new List<Section>();
            Relationships = new List<Relationship>();
            Tags = new List<EntityTagJunction>();
        }

        [DataMember]
        public long Id { get; set; }
        DateTime createdUtc;

        public DateTime CreatedUtc
        {
            get { return createdUtc; }
            set
            {
                if (value.Kind != DateTimeKind.Utc)
                {
                    createdUtc = DateTime.SpecifyKind(value, DateTimeKind.Utc);
                }
                else
                {
                    createdUtc = value;
                }
            }
        }

        DateTime modifiedUtc;

        public DateTime ModifiedUtc
        {
            get { return modifiedUtc; }
            set
            {
                if (value.Kind != DateTimeKind.Utc)
                {
                    modifiedUtc = DateTime.SpecifyKind(value, DateTimeKind.Utc);
                }
                else
                {
                    modifiedUtc = value;
                }
            }
        }

        public long OwnerId { get; set; }

        public virtual Owner Owner { get; set; }

        [DataMember]
        public string Name { get; set; }

        public override string ToString()
        {
            return Name;
        }

        [DataMember]
        public string Description { get; set; }


...
    } 



Obviously there are properties for foreign keys and time stamps of the database, which should not concern the client programs. The DataContractAttribute provides a clear semantic way of cherry picking class members for client proxy classes. This is a fairly basic practice in WCF, and WebApiClientGen endorse such practice for ASP.NET Web API.

Last edited Sep 21, 2015 at 10:49 AM by zijianhuang, version 2