简体   繁体   English

Wpf Mvvm Entity Framework 数据库优先绑定

[英]Wpf Mvvm Entity Framework database-first Binding

I'm building an app using Wpf Mvvm Entity Framework database-first.我正在使用 Wpf Mvvm Entity Framework 数据库优先构建一个应用程序。 My model is auto generated so I can't put the NotifyPropertyChanged in the entity.. so I rewrite all the stuff in my viewModel witch is ugly..我的模型是自动生成的,所以我不能将NotifyPropertyChanged放在实体中。

I don't think I'm clear so a sample of code, won't post everything for more clarity.我认为我不清楚所以代码示例,为了更清楚,不会发布所有内容。

The user control用户控制

<TextBox Name="tbClientNumber" Text="{Binding ClientNumber,
         UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/> 

The ViewModel class:视图模型类:

public class ClientManagerViewModel : BaseViewModel
{
    public int ClientNumber
    {
        get { return _clientNumber; }
        set
        {
            _clientNumber= value;
            RaisePropertyChanged("ClientNumber");
        }
    }
}

Auto-generated entity:自动生成的实体:

public partial class Client
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Client()
    {
    }

    public int idClient { get; set; }
    public int ClientNumber{ get; set; }
 }

Thank you all in advance谢谢大家

If you don't want to wrap the entity classes, Fody might help you.如果您不想包装实体类,Fody 可能会帮助您。 You can implement INotifyPropertyChanged on a partial class definition.您可以在INotifyPropertyChanged类定义上实现INotifyPropertyChanged I have not tried yet though.我还没有尝试过。

All classes that implement INotifyPropertyChanged will have notification code injected into property setters.所有实现 INotifyPropertyChanged 的​​类都会将通知代码注入到属性设置器中。

https://github.com/Fody/PropertyChanged https://github.com/Fody/PropertyChanged

Actually I usually simply wrap them like you did.其实我通常只是像你一样把它们包起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM