TispSpotContentRepository.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Microsoft.EntityFrameworkCore;
  2. using MySql.Data.MySqlClient;
  3. using Ropin.Inspection.Model.Entities;
  4. using Ropin.Inspection.Repository.Interface;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Linq.Expressions;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace Ropin.Inspection.Repository
  12. {
  13. public class TispSpotContentRepository : RepositoryBase<TISP_SpotContent, Guid>, ITispSpotContentRepository
  14. {
  15. public TispSpotContentRepository(InspectionDbContext dbContext) : base(dbContext)
  16. {
  17. }
  18. public IEnumerable<TISP_Content> GetBySpotCodeAsync(Guid id)
  19. {
  20. MySqlConnector.MySqlParameter[] parameters = new[]{new MySqlConnector.MySqlParameter("Id", id),new MySqlConnector.MySqlParameter("Name", "zhansan")};
  21. var contentlist = EntityFrameworkCoreExtensions.SqlQuery<TISP_Content>(DbContext.Database, "select A.* from TISP_Content A, TISP_Spot B ,TISP_SpotContent C WHERE A.C_ID = C.C_ContentCode AND B.C_Code = C.C_SpotCode AND C.C_SpotCode = @Id", parameters);
  22. //var contentlist = (from t1 in DbContext.TISP_Content
  23. // join t2 in DbContext.TISP_SpotContent on t1.C_ID equals t2.C_ContentCode
  24. // select t1).AsEnumerable();
  25. return contentlist;
  26. }
  27. public Task DeleteByConditionAsync(Expression<Func<TISP_SpotContent, bool>> expression)
  28. {
  29. return Task.FromResult(DbContext.Set<TISP_SpotContent>().Where(expression).AsEnumerable());
  30. }
  31. public Task<int> DeleteBySpotIdAsync(Guid spotId)
  32. {
  33. MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("Id", spotId) };
  34. int result = EntityFrameworkCoreExtensions.ExecuteSqlNoQuery(DbContext.Database, "DELETE from TISP_SpotContent WHERE C_SpotCode = @Id", parameters);
  35. return Task.FromResult(result);
  36. }
  37. }
  38. }