Mysql 将DateTime属性映射到时间戳mysq+;氟纤维酸盐

Mysql 将DateTime属性映射到时间戳mysq+;氟纤维酸盐,mysql,fluent-nhibernate,mapping,Mysql,Fluent Nhibernate,Mapping,我对fluentNhibernate和MySQL有点问题。 我想映射我的实体: public class Topic { public Topic() { ParentTopic = null; } public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual DateTime CreatedAt { get

我对fluentNhibernate和MySQL有点问题。 我想映射我的实体:

public class Topic
{
    public Topic()
    {
        ParentTopic = null;
    }

    public virtual Guid Id { get; set; }
    public virtual string Name { get; set; }
    public virtual DateTime CreatedAt { get; private set; }
    public virtual Guid CreatedBy { get; set; }
    public virtual IList<Post> Posts { get; set; }
    public virtual Topic ParentTopic { get; set; }
}
公共类主题
{
公共话题()
{
ParentTopic=null;
}
公共虚拟Guid Id{get;set;}
公共虚拟字符串名称{get;set;}
公共虚拟日期时间CreatedAt{get;private set;}
由{get;set;}创建的公共虚拟Guid
公共虚拟IList Posts{get;set;}
公共虚拟主题ParentTopic{get;set;}
}
指向具有相同名称的表。我最大的问题是如何映射
CreatedAt
,以便在数据库中获得一个时间戳,该时间戳仅在插入时更改,在更新时忽略


thx;)

找到了我的小问题的答案:)

公共类TopicMap:ClassMap
{
公共主题地图()
{
表(“主题”);
Id(t=>t.Id).GeneratedBy.Guid();
Map(t=>t.CreatedAt).Not.Nullable().Generated.Insert().CustomSqlType(“时间戳”);
Map(t=>t.CreatedBy).Not.Nullable();
Map(t=>t.Name).Not.Nullable().Length(500);
有许多(t=>t.Posts);
引用(t=>t.ParentTopic).Nullable().Cascade.All().ForeignKey(“FK_-Topic_-ParentTopic”);
}
}
这将在我的单元测试中起作用。希望今后不会产生更大的问题


如果有人对此有疑问,请告诉我。

没问题,只是一个建议
GeneratedBy.Guid()
是不必要的,因为Fluent NHibernate可以从属性中找出如何生成它。
public class TopicMap : ClassMap<Topic>
{
    public TopicMap()
    {
        Table("Topics");
        Id(t => t.Id).GeneratedBy.Guid();
        Map(t => t.CreatedAt).Not.Nullable().Generated.Insert().CustomSqlType("timestamp");
        Map(t => t.CreatedBy).Not.Nullable();
        Map(t => t.Name).Not.Nullable().Length(500);
        HasMany(t => t.Posts);
        References(t => t.ParentTopic).Nullable().Cascade.All().ForeignKey("FK_Topic_ParentTopic");
    }
}