Objekte können hinzugefügt werdne
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using KanSan.Base.Interfaces;
|
||||
using KanSan.Base.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,6 +20,7 @@ namespace KanSan.Base
|
||||
this.context = context;
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
this.dbSet = context.Set<TEntity>();
|
||||
|
||||
}
|
||||
public virtual void Delete(TEntity entityToDelete)
|
||||
{
|
||||
@@ -33,9 +35,15 @@ namespace KanSan.Base
|
||||
Delete(entityToDelete);
|
||||
}
|
||||
|
||||
public IEnumerable<TEntity> GetAll(string include)
|
||||
{
|
||||
return dbSet.Include(include);
|
||||
}
|
||||
|
||||
public IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "")
|
||||
{
|
||||
IQueryable<TEntity> query = dbSet;
|
||||
|
||||
|
||||
if (filter != null)
|
||||
{
|
||||
@@ -72,9 +80,30 @@ namespace KanSan.Base
|
||||
dbSet.Add(entity);
|
||||
}
|
||||
|
||||
public void Update(TEntity entityToUpdate)
|
||||
public IQueryable<TEntity> Include(params Expression<Func<TEntity,object>>[] includeExpressions)
|
||||
{
|
||||
dbSet.Attach(entityToUpdate);
|
||||
IQueryable<TEntity> query = null;
|
||||
foreach(var include in includeExpressions)
|
||||
{
|
||||
query = dbSet.Include(include);
|
||||
}
|
||||
return query ?? dbSet;
|
||||
}
|
||||
|
||||
public void Update(TEntity entityToUpdate, bool attach = true)
|
||||
{
|
||||
if (!attach)
|
||||
{
|
||||
var d = context.Entry(entityToUpdate);
|
||||
if (d != null)
|
||||
{
|
||||
d.State = EntityState.Detached;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dbSet.Attach(entityToUpdate);
|
||||
}
|
||||
IDatabaseEntry x = (entityToUpdate as IDatabaseEntry);
|
||||
if(x == null)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user