我怎样才能刷新我的背景?我有基于我的数据库中的视图的实体,当我对一个表具有视图导航属性的实体进行更新时,实体是更新但视图不刷新符合新的更新...只是想再次从Db数据.谢谢!
我想知道使用语句和创建公共变量之间的最佳方法是什么.我的例子如下:我有一个继承自一次性的经理类,这个类可以访问我的dbcontext和方法.我现在正在做的是在我的cs类上对该类进行操作,并根据我的需要创建和销毁我的对象.例如:
public class StudentManager: IDisposable
{
private ISchoolUnitOfWork _unitOfWork;
public StudentManager()
{
_unitOfWork = new SchoolUnitOfWork();
}
public IEnumerable<Student> GetStudents()
}
Run Code Online (Sandbox Code Playgroud)
在我的cs课上,我做了:
private IEnumerable<Stundets> GetStudents()
{
using (StudentManager manager = new StudentManager())
{
return = manager.GetStudents();
}
}
Run Code Online (Sandbox Code Playgroud)
要么
private StudentManager = new Studentmanager();
Run Code Online (Sandbox Code Playgroud)
最好的方法是什么:拥有我的StudentManager实例(只是创建连接并在离开页面时销毁)或使用using
?
我有点困惑.提前致谢!
我在同一个管理器上更新我的上下文,在我的上下文中调用save,这是我的工作单元的接口,我不直接访问上下文,但是当我构造它时,我构造了一个类型我的工作单元.
我确实节省了对经理的粗暴操作.所以在我的经理上更新,插入,修改我调用save方法,例如:
public class StudentManager....
public Student UpdateStudent(Student student)
{
IStudentService service = new StudentService(_unitOfWork.StudentRepository);
Student student= service.Update(student);
_unitOfWork.Save();
return student;
}
Run Code Online (Sandbox Code Playgroud)
一般来说,我有一个接口IUnitOfWork和一个UnitOfWork,也有一个IRepository和一个存储库.我只是使用一个管理器来直接实例化我的UnitOfWork,但是有一个管理员......我认为这是合法且有用的!
我试图从我的通用存储库更改我的通用检索方法.但是我想要为includeproperties传递一个字符串来传递这个:params Expression<Func<TEntity, object>>[] includeProperties = null
事情就是当我调用这个方法时:
public virtual IEnumerable<TEntity> Retrieve(Expression<Func<TEntity, bool>> filter = null, params Expression<Func<TEntity, object>>[] includeProperties = null)
Run Code Online (Sandbox Code Playgroud)
我想要例如: TEntityExample.Retrieve(filter: c=>c.Id=Id, includeProperties:c=> c.propertynav1, e=> e.propertynav1.propertynav3, e=> e.Prop4)
或者只是不需要导航属性 TEntityExample.Retrieve(filter: c=>c.Id=Id)
但不知道为什么includeProperties:
不工作,不被接受,任何人都知道为什么,或者我做错了什么.我希望有可能不通过includeProperties或通过指定传递它includeProperties:
public virtual IEnumerable<TEntity> Retrieve(Expression<Func<TEntity, bool>> filter = null, string includeProperties = "")
{
IQueryable<TEntity> query = _dbSet;
if (filter != null)
{
query = query.Where(filter);
}
if (!string.IsNullOrEmpty(includeProperties))
{
foreach (var includeProperty in includeProperties.Split
(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query …
Run Code Online (Sandbox Code Playgroud)