Created
October 30, 2013 19:36
-
-
Save PhilMurwin/7238834 to your computer and use it in GitHub Desktop.
Use EF and Context to send custom SQL string to database
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
/// <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