Skip to content

Instantly share code, notes, and snippets.

@gabrielgreen
Created May 18, 2012 21:25
Show Gist options
  • Save gabrielgreen/2727674 to your computer and use it in GitHub Desktop.
Save gabrielgreen/2727674 to your computer and use it in GitHub Desktop.
ObjectSet Extensions
public static class ObjectSetExtensions
{
public static int IdByName<T>(this ObjectSet<T> set, string name) where T : class
{
int id = set.ToList()
.Where(c => c.MemberValue<string>("name") == name)
.Select(c => c.MemberValue<int>("id"))
.FirstOrDefault();
if (id != default(int))
{
return id;
}
else
{
throw new Exception(string.Format("The {0} named {0} does not exist.", typeof(T).Name, name));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment