Skip to content

Instantly share code, notes, and snippets.

@PhilMurwin
Created October 30, 2013 19:36
Show Gist options
  • Save PhilMurwin/7238834 to your computer and use it in GitHub Desktop.
Save PhilMurwin/7238834 to your computer and use it in GitHub Desktop.
Use EF and Context to send custom SQL string to database
/// <summary>
/// Checks the Files for the specified event and category to ensure the files haven't already been generated
/// </summary>
/// <param name="eventID">Event to check for existing files</param>
/// <param name="fileCategory">Category of files to check the existence of</param>
/// <returns></returns>
public static bool FilesExist(int eventID, string fileCategory)
{
bool filesExist = false;
using (var db = new MyContext())
{
const string sql = "select 1 from TABLENAME where EventID = @EventID and Category = @Category";
SqlParameter eventIDParam = new SqlParameter("@EventID", eventID);
SqlParameter categoryParam = new SqlParameter("@Category", fileCategory);
filesExist = db.Database.SqlQuery<Int32>(sql, new object[] { eventIDParam, categoryParam }).Any();
}
return filesExist;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment