首页 \ 问答 \ FluentNhibernate,检索部分对象图(FluentNhibernate, retrieve partial Object Graph)

FluentNhibernate,检索部分对象图(FluentNhibernate, retrieve partial Object Graph)

因此,我将使用FluentNHibernate调用存储库来检索复杂对象图的根对象。 但对于某些子级别对象,我不想检索所有元素,而只检索日期参数等于某些条件的元素。 在下面的代码中,我希望OrderTime字段以这种方式过滤较低级别的Order对象。

含义我想检索所有用户的所有用户组,但每个用户的订单对象只包含来自特定日期或日期范围的订单。

那么我对如何检索这个对象图有什么选择呢? 我不想延迟加载,我只想指定一些不同的检索条件,这些条件永远不会改变。 所以它们可以是存储库的独立功能,就像最后建议的那样。 但是,我将如何编写这些方法,如何指定这些条件?

对象:

public class UserGroup
{
    public int Id;
    public IList<User> Users;
}

public class User
{
    public int Id;
    public string Name;
    public IList<Order> Orders;
}

public class Order
{
    public int Id;
    public decimal Price;
    public System.DateTime OrderTime;
}

库:

public class UserGroupRepository
{    
    public List<UserGroup> GetAll()
    {
        using (ISession session = FNH_Manager.OpenSession()) {
            dynamic obj = session.CreateCriteria(typeof(UserGroup)).List<UserGroup>();
            return obj;
        }
    }
}

潜在的新存储库方法:

public List<UserGroup> GetAll_FilterOrderDate(System.DateTime _date)
{
}

public List<UserGroup> GetAll_FilterOrderDate(List<System.DateTime> _dates)
{
}

So I will call a repository to retrieve the root object of a complex object graph, using FluentNHibernate. But for some sub-level objects I don't want to retrieve all elements, but only those where a date parameter equals certain condition. In below code, I want the lower level Order object to be filtered in this way by the OrderTime field.

Meaning I want to retrieve all UserGroups, with all Users, but the Orders object of each User shall only contain orders from a specific date or date range.

So what are my options on how to retrieve this object graph? I don't want lazy loading, I just want to specify a handful of different retrieval conditions, which will never change. So they can be separate functions of the repository, like suggested at the end. But how would I go about coding those methods, how to specify these conditions?

Objects:

public class UserGroup
{
    public int Id;
    public IList<User> Users;
}

public class User
{
    public int Id;
    public string Name;
    public IList<Order> Orders;
}

public class Order
{
    public int Id;
    public decimal Price;
    public System.DateTime OrderTime;
}

Repository:

public class UserGroupRepository
{    
    public List<UserGroup> GetAll()
    {
        using (ISession session = FNH_Manager.OpenSession()) {
            dynamic obj = session.CreateCriteria(typeof(UserGroup)).List<UserGroup>();
            return obj;
        }
    }
}

Potential new Repository methods: ?

public List<UserGroup> GetAll_FilterOrderDate(System.DateTime _date)
{
}

public List<UserGroup> GetAll_FilterOrderDate(List<System.DateTime> _dates)
{
}

原文:https://stackoverflow.com/questions/7071291
更新时间:2021-11-13 16:11

最满意答案

在python中,您可以使用name属性获取。

newdoc = request.FILES['docfile']
newdoc.name # file name

Andv如果你希望在模板中看到这里是代码

{% for document in documents %}
{{ document.file.filename }}
{% endfor }}

在模型对象中

newdoc = Document.objects.get(id=1)
newdoc.docfile.url # url of the file
newdoc.docfile.path # exact path

In python you can get that using name attribute.,.

newdoc = request.FILES['docfile']
newdoc.name # file name

Andv if you wish to see that in the template here is the code

{% for document in documents %}
{{ document.file.filename }}
{% endfor }}

In the model objects

newdoc = Document.objects.get(id=1)
newdoc.docfile.url # url of the file
newdoc.docfile.path # exact path

相关问答

更多
  • 问题出在您的设置文件中: STATIC_URL或MEDIA_URL有一个尾随逗号,将其变成一个元组。 The problem is in your settings file: one of STATIC_URL or MEDIA_URL has a trailing comma, which turns it into a tuple.
  • as_view()方法返回你需要用request参数调用的视图函数: return ListView.as_view(.....)(request) as_view() method returns view function which you need to call with request argument: return ListView.as_view(.....)(request)
  • 我会说你有一个slug=""的东西。 你可以使用django shell来检查这个: from yourapp.models import Thing Thing.objects.get(slug='') 根据你的模型定义, slug可以是空白的,但你的url模式不接受空白slug。 你将不得不修复你的slug字段或你的url模式。 Finally figured it out. The problem was nowhere in the code. Actually all I needed was ...
  • 解决了它。 我想fullcalendar想要一个包含json对象的列表,但我正在返回普通的json对象。 我做的是 for entry in entries: id = entry.id title = entry.title start = entry.date.strftime("%Y-%m-%dT%H:%M:%S") allDay = False json_entry = {'id':id, 'start':start, 'allDay':allDay, 't ...
  • 您的Javascript中存在拼写错误。 它应该是{% csrf_token %}而不是{{ csrf_token }} 。 编辑:在您发表评论后,我仔细查看了您链接的文章。 您需要包含库fileuploader.js 。 它将使用带有正确事件处理程序的表单的id file-uploader替换占位符div。 用纯HTML创建表单不起作用。 我建议您查看Github存储库中的示例: https : //github.com/alexkuhl/file-uploader/tree/master/client ...
  • 只要Django已经在Python进程中import (例如,如果你的代码在视图函数中,它已经被import ),再次导入它将不会做“任何事情”* - 所以坚持下去,使用import django; django.__file__ import django; django.__file__ 。 现在,如果当前的Python进程没有导入Django(例如,你正在调用os.system("myscript.py")而myscript.py需要确定Django的路径),那么import django 会有点浪费 ...
  • 在您的视图功能中 def pythonhandler(request): data = DocumentForm(request.POST, request.FILES) 并在您的HTML文件中
    {% csrf_token %}

    {{ form.docfile.errors }} ...

  • 在python中,您可以使用name属性获取。 newdoc = request.FILES['docfile'] newdoc.name # file name Andv如果你希望在模板中看到这里是代码 {% for document in documents %} {{ document.file.filename }} {% endfor }} 在模型对象中 newdoc = Document.objects.get(id=1) newdoc.docfile.url # url of the fi ...
  • 来自183.91.14.60(REMOTE_ADDR)的某人正在连接到您的服务器并要求Google的主页(REQUEST_URI); 因为你没有托管谷歌这确实是可疑的。 这与Google索引机器人无关。 我也从这个IP地址在我的服务器上看到了这个请求(但不是这个错误消息)。 我的猜测是有人在扫描寻找开放代理的服务器。 我不会将www.google.com添加到任何允许的主机列表中。 如果您从同一个REMOTE_ADDR收到大量这些内容,我会考虑将该IP地址添加到/etc/hosts.deny或防火墙上的阻止 ...
  • 我认为你的问题是你试图访问一个post而不迭代posts 。 正如您在post_list视图中看到的post_list ,您有: ... return render(request, 'blog/post_list.html', {'posts': posts}) 因此,您将名为posts的变量发送到模板。 但是在您的模板中,您尝试访问post :

    {{ post.title }}

    但它不 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。