Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>ATTEMPT 1: In T4 Template that creates Entity classes, change NavigationProperty to:</p> <pre><code>public string NavigationProperty(NavigationProperty navigationProperty) { var endType = _typeMapper.GetTypeName(navigationProperty.ToEndMember.GetEntityType()); return string.Format( CultureInfo.InvariantCulture, "{0}\n\n {1} {2} {3}\n {{\n {4}get\n {{\n return _{3}; \n }}\n {5} set\n {{\n _{3}=value; OnSet{3}();\n }}\n }}\n\n {6}", string.Format(CultureInfo.InvariantCulture, "{0} _{1};",_typeMapper.GetTypeName(navigationProperty.TypeUsage), _code.Escape(navigationProperty)), AccessibilityAndVirtual(Accessibility.ForProperty(navigationProperty)), navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many ? ("ICollection&lt;" + endType + "&gt;") : endType, _code.Escape(navigationProperty), _code.SpaceAfter(Accessibility.ForGetter(navigationProperty)), _code.SpaceAfter(Accessibility.ForSetter(navigationProperty)), string.Format(CultureInfo.InvariantCulture, "partial void OnSet{0}();", _code.Escape(navigationProperty))); } </code></pre> <p>Then add in partial Entity1 Class:</p> <pre><code>Partial Class Entity1:EntityBase { public SpecificObservableCollection&lt;Entity2&gt; Entity2_Observable { get; set; } partial void OnSetEntity2() { Misc_Observable.Add(Entity2); } public class SpecificObservableCollection&lt;T&gt; : ObservableCollection&lt;T&gt; { public Action&lt;T&gt; SetValue { get; set; } protected override void InsertItem(int index, T item) { if (item != null) { base.InsertItem(index, item); } } protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { base.OnCollectionChanged(e); if (this.Count&gt;0) SetValue(this[0]); } } protected override void DoStuffOnAdd() { Entity2_Observable = new SpecificObservableCollection&lt;Entity2&gt;(); Entity2_Observable.SetValue = a =&gt; _Entity2 = a; } } </code></pre> <p>Then in EntityBase:</p> <pre><code>public abstract class EntityBase { EntityBase() { DoStuffOnAdd(); } protected virtual void DoStuffOnAdd() { } } </code></pre> <p>For IValueConverter (in order to avoid adding too many records in a 1:1 relationship)</p> <pre><code>public class CanAddValueConverter : IValueConverter { private Type _T; private DataGrid _dg; public void SetValues(DataGrid dg, Type T) { _T = T; _dg = dg; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { System.Collections.IEnumerable dgIS = value as System.Collections.IEnumerable; if (_dg != null &amp;&amp; dgIS == _dg.ItemsSource) { if (_dg.Items.Count &gt; 0) return _dg.Items.Count &lt;= System.Convert.ToInt32(parameter) &amp;&amp; _dg.Items[_dg.Items.Count - 1].GetType() != _T; else return true; } else return false; } } </code></pre> <p>then in CodeBehind, assign DataGrid to IValueConverter as well as corresponding Entity type.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload