Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add property-level Attribute to map ColumnAttribute at runtime?
    primarykey
    data
    text
    <p>From this <a href="https://stackoverflow.com/questions/12143650/how-to-add-property-level-attribute-to-the-typedescriptor-at-runtime/">question</a> we have implemented the ColumnAttribute association with the corresponding property, but when Linq to SQL tries to map this property to a Column it doesn't work.</p> <p>Our property and mapping code(from the other question):</p> <pre><code> public System.Xml.Linq.XElement Name { get { return this.name; } set { this.OnNameChanging(value); this.SendPropertyChanging(); this.name = value; this.SendPropertyChanged("Name"); this.OnNameChanged(); } } System.Data.Linq.Mapping.ColumnAttribute columnAttribute = new System.Data.Linq.Mapping.ColumnAttribute(); columnAttribute.Name = "Name"; columnAttribute.Storage = "name"; columnAttribute.DbType = "Xml NOT NULL"; columnAttribute.CanBeNull = false; columnAttribute.UpdateCheck = System.Data.Linq.Mapping.UpdateCheck.Never; PropertyOverridingTypeDescriptor propertyOverrideTypeDescriptor = new PropertyOverridingTypeDescriptor(TypeDescriptor.GetProvider(typeof(ClassToMap)).GetTypeDescriptor(typeof(ClassToMap))); PropertyDescriptor pd = TypeDescriptor.GetProperties(typeof(ClassToMap)).Cast&lt;PropertyDescriptor&gt;().ToArray().Where(prop =&gt; prop.Name == "Name").FirstOrDefault(); PropertyDescriptor pd2 = TypeDescriptor.CreateProperty( typeof(ClassToMap).GetType(), pd, // base property descriptor to which we want to add attributes // The PropertyDescriptor which we'll get will just wrap that // base one returning attributes we need. columnAttribute // this method really can take as many attributes as you like, not just one ); propertyOverrideTypeDescriptor.OverrideProperty(pd2); TypeDescriptor.AddProvider(new TypeDescriptorOverridingProvider(typeof(ClassToMap)), typeof(ClassToMap)); </code></pre> <p>Any idea how to refresh the table mapping? </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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