1
, 소형 데이터베이스의 SQL 서버, 나는 일반적인 저장소 패턴을 사용 :는 EntityFramework.sqlServerCompact과 4 Entityframework.sqlserverCompact 데이터베이스 처음에는 WPF 응용 프로그램, 내가 MVVM 아키텍처를 사용하고있다 저장소 패턴 MVVM
public interface IRepository: IDisposable
{
IQueryable<T> All<T>() where T : class;
void InsertAsync<T>(T entity) where T: class ;
Task<T> GetByIdAsync<T>(int id) where T: class ;
Task EditAsync<T>(T entity) where T : class;
Task DeleteAsync<T>(T entity) where T : class;
}
저장소를 구현하는 클래스
public class TryitRepository : IRepository
{
private readonly MyEntityContext context;
public TryitRepository()
{
this.context = new MyEntityContext();
}
public IQueryable<T> All<T>() where T : class
{
return this.context.Set<T>();
}
public void Dispose()
{
if (this.context != null) this.context.Dispose();
}
public void InsertAsync<T>(T entity) where T : class
{
this.context.Set<T>().Add(entity);
this.context.SaveChanges();
}
}
// 뷰 모델
public class ArticleViewModel : ObjectBase
{
public readonly IRepository article;
public ArticleViewModel()
{
article = new TryitRepository();
this.LoadData();
}
private void LoadCommand()
{
this.EditCommand = new CustomCommand(this.EditArticle, this.CanEditArticle);
this.SaveCommand= new CustomCommand(this.SaveArticle, this.CanSaveArticle);
this.DeleteCommand = new CustomCommand(this.DeleteArticle, this.CanDeleteArticle);
}
private bool CanSaveArticle(object obj)
{
return true;
}
private void SaveArticle(object obj)
{
Article artikel = new Article() { Name = "newarticle", Color = "Pink", Price = 125.95, Articlenr = 15547878, Items_In_Package= 12 };
article.InsertAsync<Article>(artikel);
this.LoadData();
}
,536,
SaveArticle
이 실행되면 모든 것이 잘 실행되고 목록에 새 기사가 표시되지만 (ListView) 데이터베이스에는 표시되지 않습니다. 내가 뭘 잘못 했니? 미리 감사드립니다.