문제

I want to map a model property of type TimeZoneInfo to a column in the database. In NHib, I just made an IUserType "TimeZoneInfoString" that converted back and forth and then used a typedef. How can I do this type of work using Entity Framework 4.0?

도움이 되었습니까?

해결책

Entity framework doesn't have equivalent to NHibernate's user types. You must create separate property in your entity for it and map only the string property. Somethink like:

public partial class MyEntity
{
    public TimeZoneInfo TimeZone
    {
        get
        {
            return Parse(TimeZoneInfoString);
        }
        set
        {
            TimeZoneInfoString = value.ToString();
        }
    }
}

Where this class is your partial part to autogenerated entity. TimeZoneInfoString is property mapped in your entity and Parse and ToString contains your conversion logic.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top