I have some fields in Entity Framework entities which I would like to mark as [Obsolete]. Is it possible?
I have the following auto-created code:
namespace Data.Databases
{
using System;
using System.Collections.Generic;
public partial class Address
{
public long Id { get; set; }
public string CompanyName { get; set; }
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string HouseNumber { get; set; }
}
}
I tried adding metadata like this:
namespace Data.Databases
{
[MetadataType(typeof(AddressMetadata))]
public partial class Address
{
}
public class AddressMetadata
{
[Obsolete]
public string Title { get; set; }
}
}
But that doesn't work. It compiles ok, but it doesn't show the field as obsolete in VS.
Is it something I am doing wrong or is it just not possible?
(I am using EF6 with C#4.5 in VS2012.)
You could add an interface that has the member marked as Obsolete
.
namespace Data.Databases
{
[MetadataType(typeof(AddressMetadata))]
public partial class Address : IAddress
{
}
public class AddressMetadata
{
public string Title { get; set; }
}
public interface IAddress
{
[Obsolete]
public string Title { get; set; }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With