-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
163 additions
and
46 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Text; | ||
|
||
namespace aehyok.Base | ||
{ | ||
public abstract class BaseEntity | ||
{ | ||
[Key] | ||
public string Id { get; set; } | ||
|
||
public BaseEntity() | ||
{ | ||
Id = Guid.NewGuid().ToString(); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore; | ||
using aehyok.Base; | ||
|
||
namespace aehyok.Core.EntityFrameCore.MySql | ||
{ | ||
public interface IRepository<TEntity> where TEntity : BaseEntity | ||
{ | ||
DbSet<TEntity> Entities { get; } | ||
|
||
//增加单个实体 | ||
Task<int> Insert(TEntity entity); | ||
|
||
//增加多个实体 | ||
//int Insert(IEnumerable<TEntity> entities); | ||
|
||
//更新实体 | ||
Task<int> Update(TEntity entity); | ||
|
||
//删除 | ||
Task<int> Delete(object id); | ||
|
||
//根据逐渐获取实体 | ||
Task<TEntity> GetByKey(object key); | ||
} | ||
} | ||
|
5 changes: 3 additions & 2 deletions
5
dotnet6/aehyok.Core.EntityFrameCore.MySql/Models/FlowEntityType.cs
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using aehyok.Base; | ||
using aehyok.Core.EntityFrameCore.MySql.Data; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace aehyok.Core.EntityFrameCore.MySql | ||
{ | ||
public abstract class Repository<TEntity> : IRepository<TEntity> where TEntity : BaseEntity | ||
{ | ||
MyDbContext EF = new MyDbContext(); | ||
|
||
public DbSet<TEntity> Entities | ||
{ | ||
get { return EF.Set<TEntity>(); } | ||
} | ||
|
||
DbSet<TEntity> IRepository<TEntity>.Entities => throw new NotImplementedException(); | ||
|
||
public async Task<int> Insert(TEntity entity) | ||
{ | ||
Entities.Add(entity); | ||
return await EF.SaveChangesAsync(); | ||
} | ||
|
||
public async Task<int> Insert(IEnumerable<TEntity> entities) | ||
{ | ||
Entities.AddRange(entities); | ||
return await EF.SaveChangesAsync(); | ||
} | ||
|
||
public async Task<int> Update(TEntity entity) | ||
{ | ||
EF.Entry(entity).State = EntityState.Modified; | ||
return await EF.SaveChangesAsync(); | ||
} | ||
|
||
public async Task<int> Delete(object id) | ||
{ | ||
///删除操作实现 | ||
var item = await Entities.FindAsync(id); | ||
if(item != null) | ||
{ | ||
EF.Remove<TEntity>(item); | ||
return await EF.SaveChangesAsync(); | ||
} | ||
return 0; | ||
} | ||
|
||
public async Task<TEntity> GetByKey(object key) | ||
{ | ||
return await Entities.FindAsync(key); | ||
} | ||
} | ||
} | ||
|
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.