none
Drop List Does not show Fields related to Dataset RRS feed

  • Question

  • Hi ,

    I am using mysql with EF6 , the conenctions etc work fine . I created a main form Custumers and I want to show the contacts with email , phone numbers etc . I created a Dataset with the Customer Table and i works fine but when i try to drop the fields for contacts i show only 2 fields that are not part o the dataset ( count and read only )

    It happens not only with contacts but with addresses or any othe table related to my Main Customer Table

    Can i have some help , please

    Thanks

    Paul

    Monday, December 16, 2013 6:26 PM

Answers

All replies

  • Hello,

    EF generates code from the model using T4 templates. The templates shipped with Visual Studio or downloaded from the Visual Studio gallery are intended for general purpose use. This means that the entities generated from these templates have simple ICollection<T> properties.

    However, when doing data binding it is desirable to have collection properties that implement IListSource. We need to create the ObservableListSource class above and we are now going to modify the templates to make use of this class.

    1. Open the Solution Explorer and find .edmx file

    2. Find the .tt file which will be nested under the .edmx file .tt file selected in Solution Explorer.

    3. Double-click on the ProductModel.tt file to open it in the Visual Studio editor

    4. Find and replace the two occurrences of “ICollection” with “ObservableListSource”. These are located at approximately lines 296 and 484.

    5. Find and replace the first occurrence of “HashSet” with “ObservableListSource”. This occurrence is located at approximately line 50. Do not replace the second occurrence of HashSet found later in the code.

    6. Save the .tt file. This should cause the code for entities to be regenerated. If the code does not regenerate automatically, then right click on ProductModel.tt and choose “Run Custom Tool”.

    If you now open the .cs file (which is nested under .tt) then you should see that the Products collection has the type ObservableListSource<T>.

    Compile the project.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, December 17, 2013 5:56 AM
    Moderator
  • Hello ,

    Thanks for the quick response

    I did everything according to your instructions , everything went  fine but when I recompiled i got this error

    Did I do something wrong ??

    Best Regards


    • Edited by Paul_USA Tuesday, December 17, 2013 4:06 PM
    Tuesday, December 17, 2013 2:40 PM
  • Hello,

    Oh, I am really sorry for this. It is my mistake. I forget to give the class file. It should be written like below:

    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Diagnostics.CodeAnalysis;
    using System.Data.Entity;
     
    namespace WinFormswithEFSample
    {
        public class ObservableListSource<T> : ObservableCollection<T>, IListSource
            where T : class
        {
            private IBindingList _bindingList;
     
            bool IListSource.ContainsListCollection { get { return false; } }
     
            IList IListSource.GetList()
            {
                return _bindingList ?? (_bindingList = this.ToBindingList());
            }
        }
    }

    If you want to know more regarding this issue, please refer to link below:

    http://msdn.microsoft.com/en-us/data/jj682076.aspx

    Thanks for your understanding.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 18, 2013 6:22 AM
    Moderator
  • Thank you very much for your help , I will check the link
    • Marked as answer by Paul_USA Monday, December 23, 2013 12:26 PM
    Monday, December 23, 2013 12:26 PM