이 question에서 해당 속성과 함께 ColumnAttribute 연결을 구현했지만 Linq에서 SQL로이 속성을 열에 매핑하려고하면 작동하지 않습니다. 런타임에 ColumnAttribute를 매핑하기 위해 속성 수준 Attribute를 추가하는 방법은 무엇입니까?
우리의 재산과 (다른 질문에서) 매핑 코드 : 어떻게 테이블 매핑을 새로 고치려면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<PropertyDescriptor>().ToArray().Where(prop => 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));
어떤 생각?
http://stackoverflow.com/questions/393687/how-can-i-add-이 솔루션은 여기에 상세하게 설명했다 my-attributes-to-code-generated-linq2sql-classes-properties는 여전히 작동하지 않습니다. – lorddarkangel