仅在特定命名空间下自动映射
Automapping only under specific namespace
我不知道为什么,但是有了这个设置,automap 也会尝试映射 BaseClass,我该如何解决这个问题?
The entity 'BaseClass`1' doesn't have an Id mapped. Use the Id method
to map your identity property. For example: Id(x => x.Id).
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(ConnectionString).ShowSql())
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Foo.E.MenuItem>()
.Where(t => t.Namespace == "Foo")
.Setup(cfg => { cfg.FindIdentity = member => member.Name == member.DeclaringType.Name + "Id"; }))
.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
.BuildSessionFactory();
命名空间 X
public partial class BaseClass<T>
{
//somecode
}
命名空间 Foo
public class MenuItem : BaseClass<MenuItem>
{
public virtual int MenuItemId { get; set; }
public virtual string Text { get; set; }
public virtual int ParentId { get; set; }
public virtual IList<MenuItem> Children { get; set; }
public virtual MenuItem Parent { get; set; }
public MenuItem()
{
Children = new List<MenuItem>();
}
}
IgnoreBase 解决了我的问题。
.Mappings(m => m.AutoMappings.Add( AutoMap.AssemblyOf<T>()
.IgnoreBase(typeof(BaseClass<>))
我不知道为什么,但是有了这个设置,automap 也会尝试映射 BaseClass,我该如何解决这个问题?
The entity 'BaseClass`1' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id).
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(ConnectionString).ShowSql())
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Foo.E.MenuItem>()
.Where(t => t.Namespace == "Foo")
.Setup(cfg => { cfg.FindIdentity = member => member.Name == member.DeclaringType.Name + "Id"; }))
.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
.BuildSessionFactory();
命名空间 X
public partial class BaseClass<T>
{
//somecode
}
命名空间 Foo
public class MenuItem : BaseClass<MenuItem>
{
public virtual int MenuItemId { get; set; }
public virtual string Text { get; set; }
public virtual int ParentId { get; set; }
public virtual IList<MenuItem> Children { get; set; }
public virtual MenuItem Parent { get; set; }
public MenuItem()
{
Children = new List<MenuItem>();
}
}
IgnoreBase 解决了我的问题。
.Mappings(m => m.AutoMappings.Add( AutoMap.AssemblyOf<T>()
.IgnoreBase(typeof(BaseClass<>))