我如何编写 HQL 来获取它?

发布于 2024-09-17 18:07:20 字数 938 浏览 2 评论 0原文

我有一个叫做大陆和国家的课程。

大陆类具有国家/地区集合:

    private ISet<Country> _countries;
    public virtual ISet<Country> Countries
    {
        get { return _countries; }
        set { _countries = value; }
    }

我想编写一个 HQL 查询,该查询将获取所有拥有国家/地区的大陆,至少有一个国家/地区的 CountryName =“A”

我的国家/地区类具有属性:

    public virtual string CountryName { get; set; }

并且我有我的 . hbm.xml 文件包含 Continent 和 Country 对象的 Db 关系信息。

我应该如何在这里写我的 HQL:

public IList<Continent> GetContinentsWithCountriesStartingWithLetter(char letter)
        {

            string query = ":letter"; //The query to be used
            return
                _session
                    .CreateQuery(query)
                    .SetString("letter", letter.ToString())
                    .List<Continent>();
        }

谢谢!

I have a class called Continent and Country.

Continent class has Country collection:

    private ISet<Country> _countries;
    public virtual ISet<Country> Countries
    {
        get { return _countries; }
        set { _countries = value; }
    }

I want to write an HQL query that will get all the continents that have countries at least one country with CountryName = "A"

My country class has property:

    public virtual string CountryName { get; set; }

And I have my .hbm.xml files have the Db relation information for both the Continent and Country objects.

How should I write my HQL here:

public IList<Continent> GetContinentsWithCountriesStartingWithLetter(char letter)
        {

            string query = ":letter"; //The query to be used
            return
                _session
                    .CreateQuery(query)
                    .SetString("letter", letter.ToString())
                    .List<Continent>();
        }

Thanks!

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

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

发布评论

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

评论(1

紫罗兰の梦幻 2024-09-24 18:07:20
return _session
    .CreateQuery("from continent in Continent inner join continent.Countries country where country.Name like :letter")
    .SetString("letter", letter)
    .List<Continent>();
return _session
    .CreateQuery("from continent in Continent inner join continent.Countries country where country.Name like :letter")
    .SetString("letter", letter)
    .List<Continent>();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文