wpf - EntityWrapper Confusion -


wpf

entity framework 6.0

database first, entities generated tt file.

i'm having problems entitywrapper, , can't find useful information it.

i have entities, when generated looks this:

//generated code public partial class scm_supplierdepot : ipartsentity, inotifypropertychanged {     [...]     public virtual dms_address dms_address { get; set; } }  public partial class dms_address : ipartsentity, inotifypropertychanged {     //shortened brevity      public system.guid addressid  { get; set; }     public string streetnumber  { get; set; }     public string streetname  { get; set; }     public string apartmentnumber  { get; set; }     public string city  { get; set; }     public string stateprovince  { get; set; }     public string postalcode  { get; set; }     public string housename  { get; set; }     public string country  { get; set; }     public string address2  { get; set; }     public string county  { get; set; }      //inotifypropertychanged      [..] } 

i extend address class interface:

public partial class dms_address : iaddress {  }   public interface iaddress {     string streetnumber { get; set; }     string streetname { get; set; }     string apartmentnumber { get; set; }     string address2 { get; set; }     string city { get; set; }     string stateprovince { get; set; }     string postalcode { get; set; }     string county { get; set; }     string country { get; set; }         } 

i having confusion , issues around getting dms_address entity scm_supplierdepot entity. in cases can cast depot.dms_address iaddress , work entity no issues.

but when try binding object custom control, actual object control receives entitywrapper< dms_address > or entitywrapperwithoutrelationships< dms_address >

i had make control's dependency property accept object, rather iaddress prefer. cannot work object will not cast iaddress. can't cast entitywrapper can't figure out correct namespace include.

    public static readonly dependencyproperty addressproperty = dependencyproperty.register("address", typeof(object), typeof(addressform), new frameworkpropertymetadata(null, addresschanged));     public object address      {         { return (object)getvalue(addressproperty); }         set { setvalue(addressproperty, value); }     } 

more information custom control , dependency property issue can read in previous question: wpf custom control: dependencyproperty never set (on 1 of many properties)

questions:

  • can explain me going on here?
  • i don't understand wrapper coming from. how can make go away?
  • how can control receive iaddress instead of wrapper?
  • or how can cast entitywrapper object iaddress can access properties in code? (oddly enough template bindings work fine)

i figured out how needed using reflection.

        type objecttype = address.gettype();         type iadd = objecttype.getinterface("iaddress");          if (iadd != null)         {             propertyinfo info = objecttype.getproperty("stateprovince");             if (info != null)             {                 string currentprovince = info.getvalue(address) string;                  if (currentprovince != newvalue)                     info.setvalue(address, newvalue);             }         } 

i still stumped on why i'm seeing behaviour; if has interface, why can't cast it?

type iadd = address.gettype().getinterface("iaddress"); //iadd not null, iaddress ia = (address iaddress); //ia null 

.

in end managed switch code around make of code unnecessary >.<


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -