简体   繁体   English

映射中的强制类型转换,FluentNhibernate

[英]Cast type in mapping, FluentNhibernate

I have this table where a few columns are set to types that I dont want. 我在此表中将一些列设置为不需要的类型。 For instance.. a column named createDate that is set to a nvarchar(50).. which by default will be treated as a string.. But I dont want it to be mapped as a string, I want it to be mapped as a DateTime-object. 例如,。名为createDate的列设置为nvarchar(50)..默认情况下,该列将被视为字符串。。但是我不希望将其映射为字符串,我希望将其映射为字符串。 DateTime对象。 So how would I cast the string into a DateTime-object, during the mapping-process.. 因此,在映射过程中如何将字符串转换为DateTime对象。

Thanks in advance 提前致谢

Basically, your mapping class is unaware of DataBase types. 基本上,您的映射类不知道数据库类型。 You can design your model with DateTime Properties and map those to the ill-typed Columns, hoping the conversion will work given the present format. 您可以使用DateTime属性设计模型,然后将它们映射到类型不正确的Columns,希望在给定当前格式的情况下转换将起作用。 I should also look up if it is possible to pass in a FormatString to parse against, if I were to try this without success. 我也应该检查是否有可能传入FormatString进行解析,如果我尝试不成功的话。

public class Appointment
{
    public DateTime Start { get; set; }
    public DateTime End { get; set; }
}

public class AppointmentMap : ClassMap<Appointment>
{
    public AppointmentMap()
    {
        Map(x => x.Start, "StartDateStringColumn");
        Map(x => x.End, "EndDateStringColumn");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM