Search code examples
c#entity-frameworksilverlight-5.0wcf-ria-services

how to put 2 collection together in c#?


I use Entity Framwork + Wcf Ria Service for Silverlight application.

Suppose there is a property defined in VM like:

  private IEnumerable<MyEntity> _myEntitys;
        public IEnumerable<MyEntity> MyEntitys
        {
            get { return _myEntitys;}
            set
            {
                if _myEntitys;!= value)
                {
                    _myEntitys;= value;
                    RaisePropertyChanged("MyEntitys");
                }
            }
        }

then I have a single instance of MyEntity, say it's CurrentMyEntity, and a list of MyEntity, it's an EntityCollection, say it's MyMyEntityList with 2 records.

Then I want to put those together and assign it to MyEntitys. it means MyEntitys should have 3 records.

As IEnumerable is readonly, no Add method availavle. How to do it in one line of code or expression for this case?


Solution

  • What about:

    MyEntitys = MyEntityList.Concat(new[] {CurrentMyEntity});