In WPF MVVM ,How to design Models when not using Entity Framework

krishna 466 Reputation points

I have a WPF application which uses code behind and 3 tier architecture using ADO.NET.We cant use Entity Framework as need paid license for using it with AS400 Database.I am trying to use MVVM now for newer projects .But most tutorials in the internet are with Entity Framework,its kind of confusing to understand following different tutorials/videos in internet . My doubt is- We use a table in Database for getting key,value pairs and bind it in code behind to drop down based on search criteria .I wanted to start using dropdown Binding for this using MVVM.So for that i created a Models class,this contains all fields similar to my table

public class ApplParModel  
    public string AppName { get; set; }  

    public string ParName { get; set; }  

    public string ParValue { get; set; }  

    public string ParDescription { get; set; }  

    public string ParNum { get; set; }  

    public DateTime ParDate { get; set; }  

    public DateTime UpdateDate { get; set; }  

    public DateTime UpdateTime { get; set; }  


I have few doubts about the model:

1) I will only always use 2 fields key and value for drop down always public string ParValue { get; set; } public string ParDescription { get; set; }

the rest of the fields are never used ,should i still add rest of the table fields in Models class

2) My database has column names like this APAPPLNAME APTYPE

should i create getters and setters with the column names? public string APAPPLNAME{ get; set; } instead of public string AppName { get; set; }

my plan was in select query to have "select APPLNAME as AppName" etc

3) We have lots of sub projects with different views but certain dropdowns or key/value pairs like franchise,branch,department,country are used throughout ,is it good to have one model for all projects or separate model for each view.I understand DRY principle should be used ,but i think there will be INotifyPropertyChanged events which may be different for different views and we can also customize some stuff in getters and setters for each view

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,694 questions
0 comments No comments
{count} votes

Accepted answer
  1. Hui Liu-MSFT 46,961 Reputation points Microsoft Vendor
    1. For fields that are never used, there is no need to add properties for the corresponding fields in the Model.
    2. Yes, the get and set accessor needs to be added. You could use the APPLNAME in the AppName correspondence table in the Model.
    3. Generally, each table sets a Model and then sets the ViewModel for binding according to the needs of the View.
      Specifically designed according to your needs.

    Here is an example.



    public class Country  
        public int CountryId { get; set; }  
        public string CountryName { get; set; }  



    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful