多个 hasmany 相同的 keycolumn - 非法访问加载集合

发布于 2024-12-16 14:40:38 字数 1228 浏览 0 评论 0原文

有用。拉取数据,但出现此错误:非法访问加载集合

 public class Image : File
    {
        public virtual string ImagePath { get; set; }
    }

    public class Video : File
    {
        public virtual string VideoPath { get; set; }
        public virtual string VideoType { get; set; }
    }


   public class Service : ContentBase
    {
        public virtual IList<Image> Images { get; set; }
        public virtual IList<Video> Videos { get; set; }
    }



   public class ServiceMap:SubclassMap<Domain.Service>
    {
        public ServiceMap()
        {
            DiscriminatorValue("Service");

            HasMany(x => x.Images).KeyColumn("ContentBase");
            HasMany(x => x.Videos).KeyColumn("ContentBase");
        }
    }

public class ImageMap:SubclassMap<Image>
    {
        public ImageMap()
        {
            DiscriminatorValue("Image");

            Map(x => x.ImagePath);
        }
    }

 public class VideoMap:SubclassMap<Video>
    {
        public VideoMap()
        {
            DiscriminatorValue("Video");

            Map(x => x.VideoPath);
        }
    }

它有效。但当我查询时它给出了这个错误。我认为相同的“keycolumn”给出了这个错误。映射'i 我该怎么办?

it works. pull the data, but gives this error: illegal access to loading collection

 public class Image : File
    {
        public virtual string ImagePath { get; set; }
    }

    public class Video : File
    {
        public virtual string VideoPath { get; set; }
        public virtual string VideoType { get; set; }
    }


   public class Service : ContentBase
    {
        public virtual IList<Image> Images { get; set; }
        public virtual IList<Video> Videos { get; set; }
    }



   public class ServiceMap:SubclassMap<Domain.Service>
    {
        public ServiceMap()
        {
            DiscriminatorValue("Service");

            HasMany(x => x.Images).KeyColumn("ContentBase");
            HasMany(x => x.Videos).KeyColumn("ContentBase");
        }
    }

public class ImageMap:SubclassMap<Image>
    {
        public ImageMap()
        {
            DiscriminatorValue("Image");

            Map(x => x.ImagePath);
        }
    }

 public class VideoMap:SubclassMap<Video>
    {
        public VideoMap()
        {
            DiscriminatorValue("Video");

            Map(x => x.VideoPath);
        }
    }

it works. but it gives this error when I query. I think the same "keycolumn" gives this error to be. mapping'i How should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七婞 2024-12-23 14:40:38

您是否知道 joinalias 不会急切加载集合?这就是 Fetch 的用途。请尝试这个

var service = UnitOfWork.CurrentSession.QueryOver<Service>()
    .Fetch(x => x.Images).Eager
    .Fetch(x => x.Videos).Eager
    .Where(x => x.Id == serviceId)
    .SingleOrDefault();

更新:

时可能会抛出对加载集合的非法访问

  • 时,会话关闭
  • 在访问未初始化的集合映射和集合类型不匹配
  • 数据库不匹配

是否检查了生成的sql以查看是否NH尝试访问不存在的列或错误表上的列?

Are you aware that joinalias wont eagerload the collections? that's what Fetch is for. Try this one instead

var service = UnitOfWork.CurrentSession.QueryOver<Service>()
    .Fetch(x => x.Images).Eager
    .Fetch(x => x.Videos).Eager
    .Where(x => x.Id == serviceId)
    .SingleOrDefault();

Update:

illegal access to loading collection could be thrown when

  • session is closed when accessing not initialized collection
  • mapping and collection type mismatch
  • Database doesn't match

have you inspected the sql generated to see if NH tries to access nonexistant columns or columns on the wrong table?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文