简体   繁体   English

流利的Nhibernate如何忽略现有表中的映射列

[英]Fluent Nhibernate how to ignore mapping columns from an existing table

Is it possible to map a class in model to a table that has more columns than the model class? 是否可以将模型中的类映射到具有比模型类更多列的表? I just want to map specific columns of a table using Fluent Nhibernate . 我只想使用Fluent Nhibernate映射表的特定列。 For example the table has these columns: 例如,表具有以下列:

ProductId
ProductName
BatchNumber
StoreId

but in the model class I just want: ProductId , ProductName . 但在模型类中,我只想要: ProductIdProductName Is it possible not to include BatchNumber and StoreId in the model class? 是否可以在模型类中不包含BatchNumberStoreId

You can override mapping: 您可以覆盖映射:

public class ProductAutoMappingOverride : IAutoMappingOverride<Product> {

    public void Override(AutoMapping<Product> mapping) {
       mapping.Id(p => p.ProductId),
       mapping.Map(p => p.ProductName),
       mapping.IgnoreProperty(p => p.BatchNumber);
       mapping.IgnoreProperty(p => p.StoreId);
    }

}

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

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