Skip to content

Instantly share code, notes, and snippets.

@markdstafford
Last active December 16, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markdstafford/5461292 to your computer and use it in GitHub Desktop.
Save markdstafford/5461292 to your computer and use it in GitHub Desktop.
Code for OData 101: Using the [NotMapped] attribute to exclude Enum properties
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace WcfDataServices101.UsingTheNotMappedAttribute
{
public class AccessControlEntry
{
public int Id { get; set; }
// An Enum property cannot be mapped to an OData feed, so it must be
// explicitly excluded with the [NotMapped] attribute.
[NotMapped]
public FileRights FileRights { get; set; }
// This property provides a means to serialize the value of the FileRights
// property in an OData-compatible way.
public string Rights
{
get { return FileRights.ToString(); }
set { FileRights = (FileRights)Enum.Parse(typeof(FileRights), value); }
}
}
[Flags]
public enum FileRights
{
Read = 1,
Write = 2,
Create = 4,
Delete = 8
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment