Vì một số lý do, NHibernate cho tôi biết nó không thể chuyển đổi NHibernate.Collection.Generic.PersistentGenericSet[Ingredient]
thành System.Collection.Generic.IList[Ingredient]
, khi tôi cố gắng lấy dữ liệu từ cơ sở dữ liệu. Đây là một phiên bản simplfied lập bản đồ lớp học của tôi/thực hiện:C# - NHibernate không thể truyền NHibernate.Collection.Generic.PersistentGenericSet vào System.Collections.Generic.IList
public class Product {
protected Product() { };
public virtual Name { get; set; }
public virtual IList<Ingredient> {
get { return new List<Ingredient>(ingredients).AsReadOnly(); }
protected set { ingredients = value; }
}
private IList<Ingredient> ingredients = new List<Ingredient>();
}
-
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="LanchesAdmin.Core.Domain.Product, LanchesAdmin.Core" table="product" >
<id name="ID" generator="identity">
<column name="id" not-null="true" />
</id>
<property name="Name" column="name" length="64" not-null="true" />
<set name="Ingredients" table="ingredient" fetch="join" lazy="true" inverse="true">
<key column="product_id" />
<one-to-many class="LanchesAdmin.Core.Domain.Ingredient, LanchesAdmin.Core" />
</set>
</class>
</hibernate-mapping>
Tôi đã nhìn thấy một số câu hỏi liên quan, nhưng tất cả họ đều cho tôi biết để sử dụng IList, và đó chính xác là những gì tôi đang làm.
thử xóa việc tạo danh sách mới và cuộc gọi Chỉ đọc. – Euphoric
@Euphoric, đã thử, không thực sự tạo ra bất kỳ sự khác biệt nào. – rmobis
@Raphael_ bạn có thể đăng mã của bạn mà cuối cùng làm việc. Và nếu có thể, bạn có thể đăng mã cho 'Thành phần' (hay giải thích nó là gì). Tôi đang chạy vào một vấn đề và đang tự hỏi liệu giải pháp của bạn sẽ sửa chữa nó. Cảm ơn trước. – REMESQ