[英]Fluent NHibernate Component Mapping issue
I have a SQL Server stored procedure that I'm executing using a query string that returns a table with the following columns (ItemNumber, ItemDescription, UPC, Price, Count) representing the count of stores that an Item has for a given price. 我有一个正在使用查询字符串执行的SQL Server存储过程,该查询字符串返回一个表,表中的以下列(ItemNumber,ItemDescription,UPC,Price,Count)代表给定价格下Item的存储数量。 So Item A is 1.00 at 50 stores and 2.00 at 55 stores.
因此,项目A在50家商店中为1.00,在55家商店中为2.00。
Here is the code for executing the Fetch: 这是执行提取的代码:
private IEnumerable<RetailPrice> FetchRetailPrices(IUnitOfWork unitOfWork, string upc)
{
string StoredProcedure = "EXEC RetailPrices @UPC = :upc";
List<Parameter> parameters = new List<Parameter>
{
new Parameter("upc", upc)
};
return unitOfWork.GetRepository<RetailPrice>().Fetch(
StoredProcedure, parameters);
}
Here are my objects I'm trying to map using Fluent NHibernate: 这是我尝试使用Fluent NHibernate映射的对象:
namespace Report.Entities
{
[Serializable]
public class Item
{
public virtual string Upc { get; protected internal set; }
public virtual int ItemNumber { get; protected internal set; }
public virtual string ItemDescription { get; protected internal set; }
}
}
namespace Report.Entities
{
[Serializable]
public class RetailPrice
{
public virtual Item ItemDetails { get; protected internal set; }
public virtual decimal Price { get; protected internal set; }
public virtual int Count { get; protected internal set; }
}
}
Here is my Map: 这是我的地图:
namespace Report.Mappings
{
public class RetailPriceMap : ClassMap<RetailPrice>
{
public RetailPriceMap()
{
Id(a => a.Price).Column("Price");
Map(a => a.Count).Column("Count");
Component(a => a.ItemDetails, b =>
{
b.Map(c => c.ItemNumber).Column("ItemNumber");
b.Map(c => c.ItemDescription).Column("ItemDescription");
b.Map(c => c.Upc).Column("UPC");
});
}
}
}
Right now I'm just doing this for one item for one price and I'm getting a PropertyNotFoundException: Could not find a setter for property 'ItemNumber' in class 'Report.Entities.RetailPrice'. 现在,我只是以一个价格对一个项目执行此操作,并且我得到了PropertyNotFoundException:在类'Report.Entities.RetailPrice'中找不到属性'ItemNumber'的设置方法。
Why is the code trying to load this on the RetailPrice object instead of the Item object? 为什么代码尝试将其加载到RetailPrice对象而不是Item对象上? Does it have anything to do with running the stored procedure as a Fetch query?
它与将存储过程作为Fetch查询运行有关系吗?
Once I get that solved, how can I go about making the Item.Upc part of the Id on the RetailPriceMap? 解决问题后,该如何在RetailPriceMap上使Item.Upc成为ID的一部分?
Your built an entity for the retail price with a complete mapping. 您为零售价格建立了具有完整映射的实体。 AliasToBean transformer does not use mappings but instead mapps columns to properties by convention.
AliasToBean转换器不使用映射,而是按照约定将列映射到属性。 Change Transformer to AddEntity:
将Transformer更改为AddEntity:
public IEnumerable<TEntity> Fetch(String sql,IEnumerable<Parameter> parameters)
{
return this.BuildQuery(sql, parameters).AddEntity(typeof(TEntity)).List<TEntity>();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.