Subsonic - can anyone provide an example of using Subsonic SimpleRepository to persist a list/array of objects?

前端 未结 2 1634
深忆病人
深忆病人 2021-01-17 04:13

I\'m looking for possible ways to persist the following classes. Subsonic SimpleRepository looks like it might work, and people have said it should, when I

相关标签:
2条回答
  • 2021-01-17 04:47

    I'm not sure I'm going to answer everything you're asking here, but if I was implementing this using SimpleRepository I'd have the following models:

    public class RawYValue
    {
      public int Id { get; set; }
      public int RunDatumId { get; set; }
      public float YValue { get; set; }
    }
    
    public class RunDatum
    {
       var repo = new SimpleRepository();
    
       public int Id { get; set; }
       public int DataId { get; set; }
       public DateTime StartDateTime { get; set; }
       public TimeSpan ElapsedTime { get; set; }
    
       public IQueryable<RawYValue> RawYValues 
       { 
         get { return repo.Find<RawYValue>(rawYValue => rawYValue.RunDatumId == Id); }
       }
     }
    
    public Data
    {       
      var repo = new SimpleRepository();
    
      public int Id { get; set; }
      public string OperatorId { get; set; }
      public string SampleId { get; set; }
    
      // CAN SUBSONIC DEAL WITH THIS ARRAY OF OBJECTS???
      public IQueryable<RunDatum> RunData 
      { 
         get { return repo.Find<RunDatum>(runDatum => runDatum.DataId == Id); }
      }
    }
    

    I imagine SubSonic will have trouble pluralising some of the names so you may need to change them but hopefully this will get you started.

    0 讨论(0)
  • 2021-01-17 05:05

    To answer my own question...

    Despite some other postings I found which imply that Subsonic SimpleRepository can automatically generate a relational schema from an object model, this turns out NOT to be the case. See Rob Conery's answer to this question:

    relationships-and-lazy-loading-in-subsonic-3-0

    He's working on it, however, and it will probably be well worth the wait.

    In the meantime, I've looked at Fluent NHibernate, and this does what I want right out of the box. Their source code download has a demo project called Examples.FirstProject which demonstrates the functionality I'm looking for. Their documentation seems to be much more mature as well.

    However, NHibernate also appears more complex overall, so it will be interesting to see what develops with Subsonic.

    Edit: Heres a useful link that shows how to mangage foreign keys yourself in SimpleRepository -

    subsonic-3-simplerepository

    Have not tried it myself, but looks like it would actually work.

    0 讨论(0)
提交回复
热议问题