Last active
March 16, 2020 04:50
-
-
Save hawjeh/f12c5c03e7b2a60184ef6fd86e05b3b7 to your computer and use it in GitHub Desktop.
Sitefinity - Shell for SQL command ExecuteNonQuery
This file contains hidden or 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
| public interface IQueryService | |
| { | |
| void CreateTable(string script); | |
| void InsertRecord(string script); | |
| IList<T> SelectRecord<T>(string script); | |
| } |
This file contains hidden or 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
| public class QueryService : IQueryService, IDisposable | |
| { | |
| private PageManager _pageManager; | |
| private SitefinityOAContext _context; | |
| public QueryService() | |
| { | |
| _pageManager = PageManager.GetManager(string.Empty, ServiceConstant.QueryService.GetTransactionName()); | |
| _context = (_pageManager.Provider as IOpenAccessDataProvider).GetContext(); | |
| } | |
| public void Dispose() | |
| { | |
| _pageManager.Dispose(); | |
| _context.Dispose(); | |
| } | |
| private void CheckContext() | |
| { | |
| if (_context == null) | |
| { | |
| _context = (_pageManager.Provider as IOpenAccessDataProvider).GetContext(); | |
| } | |
| } | |
| public void CreateTable(string script) | |
| { | |
| try | |
| { | |
| CheckContext(); | |
| Logs.WriteTrace("Execute Create Table Script"); | |
| _context.ExecuteNonQuery(script); | |
| _context.SaveChanges(); | |
| } | |
| catch (Exception ex) | |
| { | |
| Logs.WriteError(ex); | |
| } | |
| } | |
| public void InsertRecord(string script) | |
| { | |
| try | |
| { | |
| CheckContext(); | |
| Logs.WriteTrace("Execute Insert Record Script"); | |
| _context.ExecuteNonQuery(script); | |
| _context.SaveChanges(); | |
| } | |
| catch (Exception ex) | |
| { | |
| Logs.WriteError(ex); | |
| } | |
| } | |
| public IList<T> SelectRecord<T>(string script) | |
| { | |
| try | |
| { | |
| CheckContext(); | |
| Logs.WriteTrace("Execute Select Record Script"); | |
| return _context.ExecuteQuery<T>(script); | |
| } | |
| catch (Exception ex) | |
| { | |
| Logs.WriteError(ex); | |
| } | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment