哪里有关于如何在 WPF 应用程序中将 Caliburn.Micro MVVM 与实体框架结合起来的说明?

发布于 2024-12-04 07:56:51 字数 550 浏览 4 评论 0原文

如何将 Caliburn.Micro MVVM 与实体框架集成以用于新的 WPF 4 应用程序? 到目前为止,我还没有找到教程。我不打算使用 Silverlight 或 RIA 服务。该应用程序(我公司的 CRM)可能会随着时间的推移而增长。我计划使用 PRISM 进行模块化,并希望将这三个框架结合起来。

请注意,我不会使用 EF Code First。 EDM 将通过将表格拖动到设计图面以生成实体来创建。为了从 Caliburn.Micro 中受益,我相信所有实体属性都需要包装才能使用 NotifyOfPropertyChange。如果是这样,我想找到某种代码生成工具来使这变得更容易。也许我需要将 EF 包装在存储库中?如果您能建议资源来帮助我回答这些问题,我将不胜感激。

谢谢!

编辑:我发布了 相关问题在这里

How can I integrate Caliburn.Micro MVVM with Entity Framework for a new WPF 4 application? I've had no luck so far finding a tutorial. I do not plan to use Silverlight or RIA Services. The application (a CRM for my company) is likely to grow over time. I plan to use PRISM for modularity and hope to combine the three frameworks.

Please note that I will not be using EF Code First. The EDM will be created by dragging tables to the design surface to generate Entities. To benefit from Caliburn.Micro I believe all Entity properties will need to be wrapped to make use of NotifyOfPropertyChange. If so I'd like to find some sort of code generation tool that would make this easier. Perhaps I need to wrap EF in a repository? If you can suggest resources to help me answer these questions it would be much appreciated.

Thanks!

Edit: I've posted a related question here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-12-11 07:56:51

MVVM 模式不关心数据访问方法,数据访问方法也不关心 MVVM 模式。首先,您可以简单地在 ViewModel 中编写查询,然后使用存储库模式重构它们。

在 PRISM 部分并结合了 3 个框架。棱镜其实并不需要。查看 Caliburn Micro 源下载中提供的 HelloScreens 示例。客户端项目中有 3 个子文件夹 /Customer /Orders 和 /Settings。它们基本上是模块,可以分成单独的项目。 这里是关于该主题的帖子。

我喜欢 CM,但您可能会考虑的另一个选择是 Lightswitch,因为它是一个公司 CRM。

编辑:
找到您喜欢的存储库模式和 EF 的示例并使用它。然后在您的 ViewModel 中并使用 DI:

public class CustomerViewModel : Screen
{
     public IRepository CustomerRepo { get; set; }
     public CustomerViewModel(IRepository customerRepo)
     {
          Customer = customer
     }

     private BindableCollection<Customer> _customers;
     public BindableCollection<Customer> Customers
     {
         get { return _customers; }
         set
         {
             _customers = value;
             NotifyOfPropertyChange(() => Customers);
         }
     }

     protected override void OnActivate()
     {
          base.OnActivate();

          Customers = CustomerRepo.GetAll();
        }   
}

The MVVM pattern doesn't care about the data access method nor does the data access method care about the MVVM pattern. To get started you can simply write the queries in your ViewModels and then later, refactor them out using a repo pattern.

On the PRISM part and combining the 3 frameworks. Prism isn't really needed. Check out the HelloScreens example that comes in the Caliburn Micro source download. There are 3 subfolders in the client project /Customer /Orders and /Settings. They're basically modules and could be separated out into separate projects. Here is a post on that subject.

I love CM but another alternative you might check out is Lightswitch since it's a company CRM.

edit:
Find an example of the repository pattern and EF you like and use that. Then in your ViewModels and using DI:

public class CustomerViewModel : Screen
{
     public IRepository CustomerRepo { get; set; }
     public CustomerViewModel(IRepository customerRepo)
     {
          Customer = customer
     }

     private BindableCollection<Customer> _customers;
     public BindableCollection<Customer> Customers
     {
         get { return _customers; }
         set
         {
             _customers = value;
             NotifyOfPropertyChange(() => Customers);
         }
     }

     protected override void OnActivate()
     {
          base.OnActivate();

          Customers = CustomerRepo.GetAll();
        }   
}
丢了幸福的猪 2024-12-11 07:56:51

有一个教程 在这里。我能够以此为基础编写一个完整的相当复杂的应用程序。

There is a tutorial here. I was able to write an entire fairly complex app just from that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文