简体   繁体   中英

what is the type of TrackableCollectionOfMyObjectNamexSjLehPL coming from EF4(entity framework)- Mvvm-WPf

I have 2 objects, lets say, Country and City- they have one to many relation,

country --> id, name

city--> id, countryid, city name

In view Model, i get the country list( everything is perfect), However, the country.cities is in the type of TrackableCollectionOfCityxSjLehPL although my service reference configuration, collection type is set to system.collections.generic.list.

in my user interface, there is the grid view that shows list of countries which is binded to to countrylist from view model, and another gridview which is binded to selectedCountry.cities

it is working, however when i try to add a new city user clicks a button , its command in view model is like:

city newcity= new City();
SelectedCountry.Cities.Add(newcity),
NotifyProperyChanged(selectedCountry)

I expect it to be added in my grid view, right?? but no! its not being add to city grid view, when i sort by clicking the column, it refreshes and i see my newly added city!

I think I should implement CollectionChanged- because the changing part is actually inside a list of my county, but since its TrackableCollectionOfCityxSjLehPL , i can't do that, and there is no information about this type, it sometimes comes sometimes not....

I don't want to seperate the objects like making another list for cities and bind that in Wpf part, because eventually i save the whole country in the end, or refresh the grid in the code behind.......

So if you saw this type of list and had a problem like this, I would be really glad if somebody gives me some information

1 - Delete all your current Service References.

2 - Add a reference to your Model assembly (project) from your ViewModels:

--MySolution
 |-- MyProject.Model
 |   |-- (Model Classes)
 |
 |-- MyProject.ViewModels
 |    |--References
 |    |   |--MyProject.Model.dll <-- You need this
 |    |
 |    |--(ViewModel Classes)
 |
 |----(etcetera)
  • This allows you to "Reuse existing Types" when creating the service reference:

    在此处输入图片说明

That will prevent that horrible TrackableCollectionOfCityxSjLehPL from ever showing up.

3 - Re-add the Service References and make sure you select the option shown above.

4 - You will probably NOT want to handle CollectionChanged in the TrackableCollection. Keep the ViewModel separate from the Model, otherwise you will run into huge maintainability / scalability issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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