小编Bik*_*Lem的帖子

在使用ORM解决方案的ASP.NET MVC中工作时,是否需要使用Repository模式?

我有点好奇其他开发人员在使用Entity Framework或NHibernate在ASP.NET MVC中编程时应用Repository模式的经验.在我看来,这种模式已经在ORM中实现了.DbContextDbSet<T>在实体框架和ISessionNHibernate中.这些Repository模式中提到的大部分问题- 如POEEDDD编目- 都是由这些ORM非常充分地实现的.即这些问题是,

  • 坚持
  • OO查看数据
  • 数据访问逻辑抽象
  • 查询访问逻辑

此外,我见过的大多数存储库模式的实现都遵循这种实现模式 - 假设我们正在开发一个博客应用程序.

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)

asp.net-mvc orm design-patterns domain-driven-design

28
推荐指数
1
解决办法
6779
查看次数

排除列在Entity Framework 4.1 Code First中可更新

有谁知道我们是否可以排除在Entity Framework 4.1 Code First中更新列?例如,我有'CreatedOn'字段,我不希望在进行编辑/更新时包含该字段.这是否可行,即选择性地从EF Code First 4.1中的更新操作中排除字段?

ef-code-first entity-framework-4.1

8
推荐指数
1
解决办法
3518
查看次数

无法在F#FSI中的WPF TextBox中输入文本

在下面的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)

wpf f#

3
推荐指数
1
解决办法
267
查看次数