Last active
December 16, 2015 16:09
-
-
Save markdstafford/5461292 to your computer and use it in GitHub Desktop.
Code for OData 101: Using the [NotMapped] attribute to exclude Enum properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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