It turns out that Entity Framework does not like the generic class EfObservableCollection.
Up vote 0 down vote favorite share g+ share fb share tw.
Building on Ladislav's answer to Entity Framework Code First and Collections of Primitive Types I'm attempting to create a wrapper type EfObservableCollection around an ObservableCollection that has an additional helper property to simplify persistence (certainly this solution has trade-offs, but it's seems workable for my domain). However, properties of type EfObservableCollection seem to be ignored by EF. No appropriate columns are created in the database.
Guessing that implementing IEnumerable might trigger EF to ignore that type, I commented out that implementation with no change in behavior. What am I missing here? Entity Class public class A { DataMember public long Id { get; set; } DataMember public string Text { get; set; } // Tags is not persisted DataMember public EfObservableCollection Tags { get; set; } } Wrapper Class ComplexType public class EfObservableCollection : IEnumerable { const string VALUE_SEPARATOR = "\x8"; // Backspace character.
Unlikely to be actually entered by a user. Assumes ASCII or UTF-8. Readonly string VALUE_SEPARATORS = new string { VALUE_SEPARATOR }; NotMapped protected ObservableCollection Collection { get; private set; } public EfObservableCollection() { Collection = new ObservableCollection(); } DataMember public string PersistHelper { get { string serializedValue = string.
Join(VALUE_SEPARATOR, Collection.ToArray()); return serializedValue; } set { Collection.Clear(); string serializedValues = value. Split(VALUE_SEPARATORS, StringSplitOptions. None); foreach (string serializedValue in serializedValues) { Collection.
Add((T)Convert. ChangeType(serializedValue, typeof(T))); // T must implement IConvertable, else a runtime exception. } } } public void Add(T item) { Collection.
Add(item); } IEnumerator GetEnumerator() { return Collection.GetEnumerator(); } System.Collections. IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } entity-framework-4 ef-code-first link|improve this question asked Dec 1 '11 at 23:10Eric J.24.6k22873 92% accept rate.
It turns out that Entity Framework does not like the generic class EfObservableCollection. If I derive a non-generic class from that class, data is persisted as expected: ComplexType public class EfObservableCollectionString : EfObservableCollection { }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.