Wpf Mvvm Entity Framework database-first Binding









up vote
-1
down vote

favorite












I'm building an app using Wpf Mvvm Entity Framework database-first. 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..



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










share|improve this question























  • Hi there, what's the issue you want to avoid? Ugly is not a good description. Please write what exactly you want to achieve
    – Jan
    Nov 10 at 4:44










  • You appear to want your Model to be a ViewModel. (I'm assuming you understand what the letters in MVVM represent.) This may mean you haven't grasped the reason for them being separate.
    – Richardissimo
    Nov 10 at 7:46











  • I thought viewmodel doesn't know anything about the view, so if i put all the property in viewModel, properties that are already existing somewhere, it sounds to me that's incorrect for the design pattern. I describe it as ugly for that reason..
    – miniboom
    Nov 10 at 19:13










  • You can put the entities and wrappers on model layer. View model will have a property ClientWrapper and the binding will be like Text="Binding ClientWrapper.ClientNumber, ... ". This might help you stackoverflow.com/questions/17143842/…
    – cactuaroid
    Nov 11 at 7:22















up vote
-1
down vote

favorite












I'm building an app using Wpf Mvvm Entity Framework database-first. 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..



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










share|improve this question























  • Hi there, what's the issue you want to avoid? Ugly is not a good description. Please write what exactly you want to achieve
    – Jan
    Nov 10 at 4:44










  • You appear to want your Model to be a ViewModel. (I'm assuming you understand what the letters in MVVM represent.) This may mean you haven't grasped the reason for them being separate.
    – Richardissimo
    Nov 10 at 7:46











  • I thought viewmodel doesn't know anything about the view, so if i put all the property in viewModel, properties that are already existing somewhere, it sounds to me that's incorrect for the design pattern. I describe it as ugly for that reason..
    – miniboom
    Nov 10 at 19:13










  • You can put the entities and wrappers on model layer. View model will have a property ClientWrapper and the binding will be like Text="Binding ClientWrapper.ClientNumber, ... ". This might help you stackoverflow.com/questions/17143842/…
    – cactuaroid
    Nov 11 at 7:22













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I'm building an app using Wpf Mvvm Entity Framework database-first. 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..



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










share|improve this question















I'm building an app using Wpf Mvvm Entity Framework database-first. 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..



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







c# wpf mvvm entity-framework-6 inotifypropertychanged






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 7:31









marc_s

567k12810961246




567k12810961246










asked Nov 10 at 4:29









miniboom

11




11











  • Hi there, what's the issue you want to avoid? Ugly is not a good description. Please write what exactly you want to achieve
    – Jan
    Nov 10 at 4:44










  • You appear to want your Model to be a ViewModel. (I'm assuming you understand what the letters in MVVM represent.) This may mean you haven't grasped the reason for them being separate.
    – Richardissimo
    Nov 10 at 7:46











  • I thought viewmodel doesn't know anything about the view, so if i put all the property in viewModel, properties that are already existing somewhere, it sounds to me that's incorrect for the design pattern. I describe it as ugly for that reason..
    – miniboom
    Nov 10 at 19:13










  • You can put the entities and wrappers on model layer. View model will have a property ClientWrapper and the binding will be like Text="Binding ClientWrapper.ClientNumber, ... ". This might help you stackoverflow.com/questions/17143842/…
    – cactuaroid
    Nov 11 at 7:22

















  • Hi there, what's the issue you want to avoid? Ugly is not a good description. Please write what exactly you want to achieve
    – Jan
    Nov 10 at 4:44










  • You appear to want your Model to be a ViewModel. (I'm assuming you understand what the letters in MVVM represent.) This may mean you haven't grasped the reason for them being separate.
    – Richardissimo
    Nov 10 at 7:46











  • I thought viewmodel doesn't know anything about the view, so if i put all the property in viewModel, properties that are already existing somewhere, it sounds to me that's incorrect for the design pattern. I describe it as ugly for that reason..
    – miniboom
    Nov 10 at 19:13










  • You can put the entities and wrappers on model layer. View model will have a property ClientWrapper and the binding will be like Text="Binding ClientWrapper.ClientNumber, ... ". This might help you stackoverflow.com/questions/17143842/…
    – cactuaroid
    Nov 11 at 7:22
















Hi there, what's the issue you want to avoid? Ugly is not a good description. Please write what exactly you want to achieve
– Jan
Nov 10 at 4:44




Hi there, what's the issue you want to avoid? Ugly is not a good description. Please write what exactly you want to achieve
– Jan
Nov 10 at 4:44












You appear to want your Model to be a ViewModel. (I'm assuming you understand what the letters in MVVM represent.) This may mean you haven't grasped the reason for them being separate.
– Richardissimo
Nov 10 at 7:46





You appear to want your Model to be a ViewModel. (I'm assuming you understand what the letters in MVVM represent.) This may mean you haven't grasped the reason for them being separate.
– Richardissimo
Nov 10 at 7:46













I thought viewmodel doesn't know anything about the view, so if i put all the property in viewModel, properties that are already existing somewhere, it sounds to me that's incorrect for the design pattern. I describe it as ugly for that reason..
– miniboom
Nov 10 at 19:13




I thought viewmodel doesn't know anything about the view, so if i put all the property in viewModel, properties that are already existing somewhere, it sounds to me that's incorrect for the design pattern. I describe it as ugly for that reason..
– miniboom
Nov 10 at 19:13












You can put the entities and wrappers on model layer. View model will have a property ClientWrapper and the binding will be like Text="Binding ClientWrapper.ClientNumber, ... ". This might help you stackoverflow.com/questions/17143842/…
– cactuaroid
Nov 11 at 7:22





You can put the entities and wrappers on model layer. View model will have a property ClientWrapper and the binding will be like Text="Binding ClientWrapper.ClientNumber, ... ". This might help you stackoverflow.com/questions/17143842/…
– cactuaroid
Nov 11 at 7:22













1 Answer
1






active

oldest

votes

















up vote
0
down vote













If you don't want to wrap the entity classes, Fody might help you. You can implement INotifyPropertyChanged on a partial class definition. I have not tried yet though.




All classes that implement INotifyPropertyChanged will have notification code injected into property setters.




https://github.com/Fody/PropertyChanged



Actually I usually simply wrap them like you did.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236001%2fwpf-mvvm-entity-framework-database-first-binding%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    If you don't want to wrap the entity classes, Fody might help you. You can implement INotifyPropertyChanged on a partial class definition. I have not tried yet though.




    All classes that implement INotifyPropertyChanged will have notification code injected into property setters.




    https://github.com/Fody/PropertyChanged



    Actually I usually simply wrap them like you did.






    share|improve this answer
























      up vote
      0
      down vote













      If you don't want to wrap the entity classes, Fody might help you. You can implement INotifyPropertyChanged on a partial class definition. I have not tried yet though.




      All classes that implement INotifyPropertyChanged will have notification code injected into property setters.




      https://github.com/Fody/PropertyChanged



      Actually I usually simply wrap them like you did.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        If you don't want to wrap the entity classes, Fody might help you. You can implement INotifyPropertyChanged on a partial class definition. I have not tried yet though.




        All classes that implement INotifyPropertyChanged will have notification code injected into property setters.




        https://github.com/Fody/PropertyChanged



        Actually I usually simply wrap them like you did.






        share|improve this answer












        If you don't want to wrap the entity classes, Fody might help you. You can implement INotifyPropertyChanged on a partial class definition. I have not tried yet though.




        All classes that implement INotifyPropertyChanged will have notification code injected into property setters.




        https://github.com/Fody/PropertyChanged



        Actually I usually simply wrap them like you did.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 6:59









        cactuaroid

        34119




        34119



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236001%2fwpf-mvvm-entity-framework-database-first-binding%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus