Hi Matt,
even better would be the ability to persist generic types, that way I would be able to strongly type the return value to T. I really wanted to have a generic class, which i could then define as CustomProperty<T>, where T is a known interface, unfortunately I can't then seem to define a Table<CustomProperty<T>> in my datacontext derived class. i have however found the solution to the original problem, a sample is below;
[Column(Name="PropertyValue", Storage="_propertyValue", DBType="IMAGE")]
public object PropertyValue
{
get
{
if (_propertyValue != null)
{
lock (_propertyValue)
{
byte[] buf = _propertyValue as byte[];
if (buf != null)
{
using (MemoryStream strm = new MemoryStream(buf))
{
BinaryFormatter fmt = new BinaryFormatter();
_propertyValue = fmt.Deserialize(strm);
}
}
}
}
// *** Return the Value ***
return(_propertyValue);
}
set
{
// *** Has the value been changed ***
if ((this._propertyValue != value))
{
// *** Raise PropertyChanging ***
this.OnPropertyChanging("PropertyValue");
// *** Update the Storage value ***
this._propertyValue = value;
// *** Raise PropertyChanged ***
this.OnPropertyChanged("PropertyValue");
}
}
}
[Updated]
I don't know why it didn't work for me before, but I think I've cracked it using the following:
/// <summary>< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
/// The Interface that special types must implement
/// </summary>
public interface ISpecialType
{
}
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
[Table(Name="SpecialType")]
public class SpecialType<T> where T : ISpecialType
{
private T _storage;
/// <summary>
///
/// </summary>
public SpecialType()
{
_storage = default(T);
}
/// <summary>
///
/// </summary>
[System.Data.DLinq.Column(Name="CustomValue", Storage="_storage", DBType="IMAGE")]
public T CustomValue
{
get{return(_storage);}
set{_storage = value;}
}
}
then declaring the table as:
public System.Data.DLinq.Table<SpecialType<ISpecialType>> SpecialTypes;
using a mixture of both the first and second samples I reckon I should now be able to do this.
Regards,
D
|