我有点好奇其他开发人员在使用Entity Framework或NHibernate在ASP.NET MVC中编程时应用Repository模式的经验.在我看来,这种模式已经在ORM中实现了.DbContext并DbSet<T>在实体框架和ISessionNHibernate中.这些Repository模式中提到的大部分问题- 如POEE和DDD编目- 都是由这些ORM非常充分地实现的.即这些问题是,
此外,我见过的大多数存储库模式的实现都遵循这种实现模式 - 假设我们正在开发一个博客应用程序.
NHibernate实现:
public class PostRepository : IPostRepository
{
private ISession _session;
public PostRepository(ISession session)
{
_session = session;
}
public void Add(Post post)
{
_session.Save(post);
}
// other crud methods.
}
Run Code Online (Sandbox Code Playgroud)
实体框架:
public class PostRepository : IPostRepository
{
private DbContext _session;
public PostRepository(DbContext session)
{
_session = session;
}
public void Add(Post post)
{
_session.Posts.Add(post);
-session.SaveChanges();
} …Run Code Online (Sandbox Code Playgroud) 有谁知道我们是否可以排除在Entity Framework 4.1 Code First中更新列?例如,我有'CreatedOn'字段,我不希望在进行编辑/更新时包含该字段.这是否可行,即选择性地从EF Code First 4.1中的更新操作中排除字段?
在下面的F#WPF代码中,当我从F#FSI显示"WPF"窗口时,我无法在文本框中输入任何文本.这与使用Windows窗体事件循环有关吗?
let txtBox = new TextBox()
txtBox.BorderThickness <- Thickness(2.)
txtBox.Margin <- Thickness(7.)
txtBox.IsReadOnly <- false
let wnd = new Window(Title = "Test", Height = 500., Width = 500.)
wnd.Content <- txtBox
wnd.Show()
Run Code Online (Sandbox Code Playgroud)
基于John Palmer的以下答案,我已使用正确的版本更新了上面的代码.下面的代码现在在F#FSI中正常工作.
let txtBox = new TextBox()
txtBox.BorderThickness <- Thickness(2.)
txtBox.Margin <- Thickness(7.)
txtBox.IsReadOnly <- false
let wnd = new Window(Title = "Test", Height = 500., Width = 500.)
wnd.Content <- txtBox
(new Application()).Run(wnd) |> ignore
Run Code Online (Sandbox Code Playgroud)