Subsonic 亚音速简单存储库一对多

Subsonic 亚音速简单存储库一对多,subsonic,subsonic3,one-to-many,simplerepository,Subsonic,Subsonic3,One To Many,Simplerepository,我上了一节课,比如: public class Video { public Guid VideoID { get; set; } public VideoCategory VideoCategory { get; set; } public int SortIndex { get; set; } public string Title { get; set; } public string Body { get; set; } public st

我上了一节课,比如:

public class Video
{
    public Guid VideoID { get; set; }
    public VideoCategory VideoCategory { get; set; }
    public int SortIndex { get; set; }
    public string Title { get; set; }
    public string Body { get; set; }
    public string Author { get; set; }
    public string Filename { get; set; }

    public new void Add()
    {
        this.VideoID = Guid.NewGuid();
        DB.Repository.Add(this);
    }
}
还有一个

public class VideoCategory
{
    public Guid VideoCategoryID { get; set; }
    public string Title { get; set; }

    public new void Add()
    {
        this.VideoCategoryID = Guid.NewGuid();
        DB.Repository.Add(this);
    }
}
然后我得到了如下代码:

        VideoCategory VideoCategory = new VideoCategory();
        VideoCategory.Title = "TestTitle";
        VideoCategory.Add();

        Video Video = new Video();
        Video.VideoCategory = VideoCategory;
        Video.SortIndex = 1;
        Video.Title = "TestTitle";
        Video.Body = "TestBody";
        Video.Author = "TestAuthor";
        Video.Filename = "TestFile.flv";
        Video.Add();

它没有将视频分类保存到我的数据库中,所以很明显我遗漏了一些东西。要保存一对多关系,还需要做些什么?

您不会错过任何东西。Simplerepository不支持开箱即用的一对多

这里有一个有用的链接,展示了如何在SimpleRepository中自己管理外键-

我自己也没有试过,但看起来它确实会起作用

Fluent Nhibernate将自动为您进行外键管理,但要复杂得多


PS如果这有帮助,请投票表决。

您可能只需执行以下操作,您可能希望整理它,但这将确保填充外键值:

public class Video
{
    protected VideoCategory videoCategory;
    public Guid ID { get; set; }
    public VideoCategory VideoCategory 
    {
        get { return videoCategory; }
        set
        {
            videoCategory = value;
            VideoCategoryId = value.ID;
        }
    }
    public Guid VideoCategoryId { get; set; }
    public int SortIndex { get; set; }
    public string Title { get; set; }
    public string Body { get; set; }
    public string Author { get; set; }
    public string Filename { get; set; }
}

public class VideoCategory
{
    public Guid ID { get; set; }
    public string Title { get; set; }
}

SimpleRepository repo = new SimpleRepository(SimpleRepositoryOptions.RunMigrations);

VideoCategory videoCategory = new VideoCategory();
videoCategory.ID = Guid.NewGuid();
videoCategory.Title = "TestTitle";
repo.Add<VideoCategory>(videoCategory);

Video video = new Video();
video.ID = Guid.NewGuid();
video.VideoCategory = videoCategory;
video.SortIndex = 1;
video.Title = "TestTitle";
video.Body = "TestBody";
video.Author = "TestAuthor";
video.Filename = "TestFile.flv";
repo.Add<Video>(video);

对于如何亲自实施,您有什么想法我猜在保存之前将添加/更新更改为设置ID?这是真的,但是有几个非常误导的答案,这意味着其他的。看看我的问题,看看这个坏建议的例子。汤姆:我绝对喜欢亚音速,它的易用性,我渴望在一个新项目中使用simplerepository;不幸的是,我遇到了这个问题,这使我成为了破坏者。迫不及待地想看到从我的代码中推断出关系模式!是的,亚音速的简单性和可用性非常好。我相信它最终会支持一对多的开箱即用,但现在还不行,唉。