简体   繁体   English

亚音速-谁能提供使用亚音速SimpleRepository持久存储对象列表/数组的示例?

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

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 asked a more general question . 当我问一个更普遍的问题时,Subsonic SimpleRepository看起来可能可行,并且人们说应该可以。

But I've been unable to find a single example of how to do this - or at least one I could understand. 但是我一直找不到一个如何做到这一点的例子-至少我能理解一个例子。

Can anyone point me to an example, or tell me how I could use Subsonic to map the following classes to a database? 谁能给我指出一个例子,或告诉我如何使用Subsonic将以下类映射到数据库?

Note that I haven't designed the database - I'm hoping Subsonic will do that for me , lazy sod that I am... 请注意, 我还没有设计数据库 - 我希望Subsonic可以为我做到这一点,我懒洋洋地...

Edit: Just to expand on the previous point - I'm hoping to have Subsonic convert my object model to a relational DB, dealing with all the Parent-Child and One-To-Many relationships that are implied. 编辑:只是为了扩展上一点-我希望Subsonic将我的对象模型转换为关系数据库,以处理所有暗示的父子关系和一对多关系。 Currently, I don't think Subsonic can do this. 目前,我认为Subsonic无法做到这一点。 But even a working example (not a code fragment) that explicitly managed foreign keys, etc in the object model would be useful. 但是即使在对象模型中显式管理外键等的工作示例 (不是代码片段)也将很有用。

Some background and notes on the classes I want to persist: 我要坚持的课程背景和注意事项:

  • they are used by the software that controls some measuring equipment 它们由控制某些测量设备的软件使用
  • the Data class contains an array of RunData objects called RunFn , which holds the data for up to 10 individual measurement runs Data类包含一个称为RunFnRunData对象数组,该数组可保存多达10次独立测量运行的数据
  • note that RunData also contains an array of floats - RawY 请注意, RunData还包含一个浮点数组-RawY
  • if necessary, we can change the arrays to some other type of collection (List<>, etc) 如有必要,我们可以将数组更改为其他类型的集合(List <>等)
  • developing in C#, VS2008, for SQL Server Express 使用C#,VS2008开发SQL Server Express

Edit: I'm using Subsonic 3.0.0.3. 编辑:我正在使用Subsonic 3.0.0.3。

public class RunData

{
    public DateTime StartDateTime { get; set; }
    public TimeSpan ElapsedTime { get; set; }

    private float[] _rawY;
    public float[] RawY
    {
        get
        {
            return _rawY;
        }
        set
        {
            _rawY = value;
        }
     }
 }

public Data
{
    public string OperatorId { get; set; }
    public string SampleId { get; set; }

    // CAN SUBSONIC DEAL WITH THIS ARRAY OF OBJECTS???
    private RunData[] _runFn;
    public RunData[] RunFn
    {
        get
        {
            return _runFn;
        }
        set
        {
            _runFn = value;
        }
    }
}

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: 我不确定我是否会回答您在此处提出的所有问题,但是如果我使用SimpleRepository实现此功能,则将具有以下模型:

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. 我想SubSonic很难将某些名称复数,因此您可能需要更改它们,但希望这可以帮助您入门。

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 . 尽管我发现其他一些帖子暗示Subsonic SimpleRepository可以根据对象模型自动生成关系模式, 但事实并非如此 See Rob Conery's answer to this question: 请参阅Rob Conery对这个问题的回答:

relationships-and-lazy-loading-in-subsonic-3-0 关系和懒加载亚音速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. 同时,我研究了Fluent NHibernate ,它确实满足了我的要求。 Their source code download has a demo project called Examples.FirstProject which demonstrates the functionality I'm looking for. 他们的源代码下载有一个名为Examples.FirstProject的演示项目,它演示了我正在寻找的功能。 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. 但是,NHibernate总体上也看起来更复杂,因此,看看Subsonic的发展将会很有趣。

Edit: Heres a useful link that shows how to mangage foreign keys yourself in SimpleRepository - 编辑:这是一个有用的链接,该链接显示了如何在SimpleRepository中自己管理外键-

subsonic-3-simplerepository 亚音速3简易存储库

Have not tried it myself, but looks like it would actually work. 我自己还没有尝试过,但是看起来它确实可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM