From ccd7b83ae843956f7870406298a7189d43dee7a8 Mon Sep 17 00:00:00 2001 From: Shinly Date: Thu, 29 Jun 2017 10:34:42 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=B1=82=EF=BC=8C=E6=94=AF=E6=8C=81=E7=A7=BB=E9=99=A4entity?= =?UTF-8?q?=E8=A1=A8=E5=90=8D=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{BlogArticle.cs => BlogArticleEntity.cs} | 2 +- .../IBlogArticleRepository.cs | 2 +- TonyBlogs.IService/IBlogArticleService.cs | 2 +- TonyBlogs.Repository/BaseRepository.cs | 22 ++++++++++++++++++- TonyBlogs.Repository/BlogArticleRepository.cs | 2 +- TonyBlogs.Service/BlogArticleService.cs | 2 +- .../Controllers/HomeController.cs | 3 --- TonyBlogs.WebApp/Views/Home/Index.cshtml | 2 +- 8 files changed, 27 insertions(+), 10 deletions(-) rename TonyBlogs.Entity/{BlogArticle.cs => BlogArticleEntity.cs} (93%) diff --git a/TonyBlogs.Entity/BlogArticle.cs b/TonyBlogs.Entity/BlogArticleEntity.cs similarity index 93% rename from TonyBlogs.Entity/BlogArticle.cs rename to TonyBlogs.Entity/BlogArticleEntity.cs index 5ff308a..70fe78d 100644 --- a/TonyBlogs.Entity/BlogArticle.cs +++ b/TonyBlogs.Entity/BlogArticleEntity.cs @@ -6,7 +6,7 @@ namespace TonyBlogs.Entity { - public class BlogArticle + public class BlogArticleEntity { /// /// diff --git a/TonyBlogs.IRepository/IBlogArticleRepository.cs b/TonyBlogs.IRepository/IBlogArticleRepository.cs index 01b1dd7..50bc6b0 100644 --- a/TonyBlogs.IRepository/IBlogArticleRepository.cs +++ b/TonyBlogs.IRepository/IBlogArticleRepository.cs @@ -6,7 +6,7 @@ namespace TonyBlogs.IRepository { - public interface IBlogArticleRepository : IBaseRepository + public interface IBlogArticleRepository : IBaseRepository { } diff --git a/TonyBlogs.IService/IBlogArticleService.cs b/TonyBlogs.IService/IBlogArticleService.cs index afd2522..2c98257 100644 --- a/TonyBlogs.IService/IBlogArticleService.cs +++ b/TonyBlogs.IService/IBlogArticleService.cs @@ -6,7 +6,7 @@ namespace TonyBlogs.IService { - public interface IBlogArticleService : IBaseServices + public interface IBlogArticleService : IBaseServices { } } diff --git a/TonyBlogs.Repository/BaseRepository.cs b/TonyBlogs.Repository/BaseRepository.cs index e165a76..1345035 100644 --- a/TonyBlogs.Repository/BaseRepository.cs +++ b/TonyBlogs.Repository/BaseRepository.cs @@ -15,7 +15,7 @@ namespace TonyBlogs.Repository public class BaseRepository : IBaseRepository where TEntity : class { private static string connStr = "server=localhost;port=3306;User Id=root;pwd=123456;Database=tony_blogs"; - private static IDbConnectionFactory connFactory = new OrmLiteConnectionFactory(connStr, MySqlDialect.Provider); + private static IDbConnectionFactory connFactory = new OrmLiteConnectionFactory(connStr, TonyMySqlOrmLiteDialectProvider.Current); protected IDbConnection db { @@ -150,4 +150,24 @@ public void CloseConnection(IDbConnection connection) connection.Close(); } } + + public class TonyMySqlOrmLiteDialectProvider : MySqlDialectProvider + { + public static TonyMySqlOrmLiteDialectProvider Current; + + static TonyMySqlOrmLiteDialectProvider() + { + Current = new TonyMySqlOrmLiteDialectProvider(); + } + + public override string GetTableName(string table, string schema = null) + { + string tableName = base.GetTableName(table, schema).ToLower(); + + tableName = tableName.Replace("entity", ""); + + return tableName; + } + + } } diff --git a/TonyBlogs.Repository/BlogArticleRepository.cs b/TonyBlogs.Repository/BlogArticleRepository.cs index a7e8060..b203900 100644 --- a/TonyBlogs.Repository/BlogArticleRepository.cs +++ b/TonyBlogs.Repository/BlogArticleRepository.cs @@ -7,7 +7,7 @@ namespace TonyBlogs.Repository { - public class BlogArticleRepository : BaseRepository, IBlogArticleRepository + public class BlogArticleRepository : BaseRepository, IBlogArticleRepository { } diff --git a/TonyBlogs.Service/BlogArticleService.cs b/TonyBlogs.Service/BlogArticleService.cs index ecd6468..23c34ea 100644 --- a/TonyBlogs.Service/BlogArticleService.cs +++ b/TonyBlogs.Service/BlogArticleService.cs @@ -8,7 +8,7 @@ namespace TonyBlogs.Service { - public class BlogArticleService : BaseService, IBlogArticleService + public class BlogArticleService : BaseService, IBlogArticleService { private IBlogArticleRepository dal; diff --git a/TonyBlogs.WebApp/Controllers/HomeController.cs b/TonyBlogs.WebApp/Controllers/HomeController.cs index af46cf9..cdff906 100644 --- a/TonyBlogs.WebApp/Controllers/HomeController.cs +++ b/TonyBlogs.WebApp/Controllers/HomeController.cs @@ -19,9 +19,6 @@ public HomeController(IBlogArticleService BlogArticleServive) public ActionResult Index() { - int b = 0; - int c = 1 / b; - var list = BlogArticleServive.QueryWhere(m => m.ID > 0); return View(list); diff --git a/TonyBlogs.WebApp/Views/Home/Index.cshtml b/TonyBlogs.WebApp/Views/Home/Index.cshtml index 0f5f029..e4f71c0 100644 --- a/TonyBlogs.WebApp/Views/Home/Index.cshtml +++ b/TonyBlogs.WebApp/Views/Home/Index.cshtml @@ -1,6 +1,6 @@ @using TonyBlogs.Entity -@model List +@model List @{ ViewBag.Title = "Index"; }