Subsonic - 任何人都可以提供使用 Subsonic SimpleRepository 来保存对象列表/数组的示例吗?

发布于 2024-08-08 20:26:18 字数 1666 浏览 3 评论 0原文

我正在寻找可能的方法来保留以下课程。 Subsonic SimpleRepository 看起来可能有用,而且当我询问 更一般的问题

但我一直无法找到一个如何做到这一点的例子 - 或者至少一个我能理解的例子。

谁能给我举个例子,或者告诉我如何使用 Subsonic 将以下类映射到数据库?

请注意,我还没有设计数据库 - 我希望 Subsonic 会为我做这件事,我是一个懒惰的家伙......

编辑:只是为了扩展上一点 - 我希望 Subsonic 将我的对象模型转换为关系数据库,处理所有隐含的父子关系和一对多关系。目前,我认为 Subsonic 无法做到这一点。但即使是在对象模型中显式管理外键等的工作示例(不是代码片段)也会很有用。

关于我想要保留的类的一些背景和注释:

  • 它们由控制某些测量设备的软件使用
  • Data 类包含一个名为 RunData 对象的数组 RunFn,最多保存数据 10 个单独的测量运行
  • 请注意,RunData 还包含一个数组 浮点数 - RawY
  • 其他类型的集合(List<> 等)
  • 如果需要,我们可以将数组更改为在 C#、VS2008、SQL Server Express 中开发的

编辑: 我正在使用 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 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.

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?

Note that I haven't designed the database - I'm hoping Subsonic will do that for me, lazy sod that I am...

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. Currently, I don't think Subsonic can do this. 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
  • note that RunData also contains an array
    of floats - RawY
  • if necessary, we can change the arrays to some other type of collection (List<>, etc)
  • developing in C#, VS2008, for SQL Server Express

Edit: I'm using 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;
        }
    }
}

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

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

发布评论

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

评论(2

把时间冻结 2024-08-15 20:26:18

我不确定我是否会回答您在这里提出的所有问题,但如果我使用 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); }
  }
}

我想 SubSonic 在对某些名称进行复数化时会遇到麻烦,因此您可能需要更改它们,但希望这能让您开始。

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.

︶葆Ⅱㄣ 2024-08-15 20:26:18

回答我自己的问题...

尽管我发现其他一些帖子暗示 Subsonic SimpleRepository 可以从对象模型自动生成关系模式,但事实证明并非如此。请参阅 Rob Conery 对此问题的回答:

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

不过,他正在努力,这可能是值得等待的。

与此同时,我研究了Fluent NHibernate,它开箱即用地满足了我的需求。他们的源代码下载有一个名为 Examples.FirstProject 的演示项目,它演示了我正在寻找的功能。他们的文档似乎也更加成熟。

然而,NHibernate 总体上也显得更加复杂,因此看看 Subsonic 的发展将会很有趣。

编辑:这是一个有用的链接,展示了如何在 SimpleRepository 中自行管理外键 -

subsonic- 3-simplerepository

我自己没有尝试过,但看起来它确实可以工作。

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.

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