1

I have a class with some string properties that represent dates in an arbitrary format. These need to remain as String properties. Is there a way, using the fluent API or something, to indicate that these column types should be datetime. And then somehow I can tell EF to marshal the data in a certain way?

Can I just use:

HasColumnType("datetime")

and if so, how would I then handle the marshalling?

Example Class:

public Class SomePOCO{

    public String SomeTimeInWierdFormat { get; set; }
    public String SomeOtherTimeInWierdFormat { get; set; }
    public String SomeString{ get; set; }
}

Is there a string format that I can massage these strings into that would allow me use HasColumnType("datetime") without any complaints?

4

1 回答 1

2

您可以使用只读属性来公开您的DateTimesas formatted strings。这很有用,因为您仍然可以拥有正确映射到数据库的属性,同时以您选择的方式公开该数据。也许是这样的:

public Class SomePOCO{

    public DateTime DateTimeColumn { get; set; }
    public string DateTimeColumnAsString { get { return this.DateTimeColumn.ToString(); } }

}
于 2013-06-12T15:34:26.170 回答