Skip to content

Commit

Permalink
1. 修改数据层,支持移除entity表名适配
Browse files Browse the repository at this point in the history
  • Loading branch information
Halifa committed Jun 29, 2017
1 parent 96ab080 commit ccd7b83
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TonyBlogs.Entity
{
public class BlogArticle
public class BlogArticleEntity
{
/// <summary>
///
Expand Down
2 changes: 1 addition & 1 deletion TonyBlogs.IRepository/IBlogArticleRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TonyBlogs.IRepository
{
public interface IBlogArticleRepository : IBaseRepository<BlogArticle>
public interface IBlogArticleRepository : IBaseRepository<BlogArticleEntity>
{

}
Expand Down
2 changes: 1 addition & 1 deletion TonyBlogs.IService/IBlogArticleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace TonyBlogs.IService
{
public interface IBlogArticleService : IBaseServices<BlogArticle>
public interface IBlogArticleService : IBaseServices<BlogArticleEntity>
{
}
}
22 changes: 21 additions & 1 deletion TonyBlogs.Repository/BaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace TonyBlogs.Repository
public class BaseRepository<TEntity> : IBaseRepository<TEntity> 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
{
Expand Down Expand Up @@ -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;
}

}
}
2 changes: 1 addition & 1 deletion TonyBlogs.Repository/BlogArticleRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace TonyBlogs.Repository
{
public class BlogArticleRepository : BaseRepository<BlogArticle>, IBlogArticleRepository
public class BlogArticleRepository : BaseRepository<BlogArticleEntity>, IBlogArticleRepository
{

}
Expand Down
2 changes: 1 addition & 1 deletion TonyBlogs.Service/BlogArticleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace TonyBlogs.Service
{
public class BlogArticleService : BaseService<BlogArticle>, IBlogArticleService
public class BlogArticleService : BaseService<BlogArticleEntity>, IBlogArticleService
{
private IBlogArticleRepository dal;

Expand Down
3 changes: 0 additions & 3 deletions TonyBlogs.WebApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion TonyBlogs.WebApp/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@using TonyBlogs.Entity

@model List<BlogArticle>
@model List<BlogArticleEntity>
@{
ViewBag.Title = "Index";
}
Expand Down

0 comments on commit ccd7b83

Please sign in to comment.