Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
New to WPF, so please bear with me...

Suppose I have 2 tables in SQL
Thing
OtherThing

Both have the exact same fields:
ID (int)
Name (string)
Description (string)
IsActive (bit/bool)
DateModified (DateTime)

So, I want to create one Model (not two) and do something like this:
BaseModel<T>()
{
  public int ID {get;set;}
  ...
}

etc. (of course, using the INotifyPropertyChanged, just trying to keep the code simple).

I want to be able to create a BaseView and BaseViewModel that would work with whatever model conforms to the Thing/OtherThing.

I am really at a loss as to what to do here to make this generic, so I don't have to have a ThingView/ThingViewModel and a OtherThingView/OtherThingViewModel...

It seems that this should be simple, but I cannot seem to figure it out. Does anyone have a code example where they could interchange various items from a dropdown list using ONE view, ONE ViewModel, and ONE datamodel?
Posted

1 solution

If both tables have identical fields, why not just use the same class for each? No need for generics.

Other than that, I don't see what your problem is. What are you trying to do and what is the specific problem you are running into?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900