有人能解释一下 Entity SQL 中的 REF、CREATEREF、DEREF、KEY 的作用吗?

发布于 2024-12-07 13:26:31 字数 46 浏览 0 评论 0原文

我找不到有关这些运算符的良好文档。有人可以提供一些使用示例并解释他们的作用吗?

I can't find good documentation on these operators. Can someone provide some examples of use and explain what they do?

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

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

发布评论

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

评论(1

无可置疑 2024-12-14 13:26:31

Entity SQL 的 CREATEREF 参考:http://msdn.microsoft。 com/en-us/library/bb386880(v=VS.90)

它用于“制作对实体集中实体的引用”。您还可以从链接中找到 REF 和 DEREF 的参考。

对于 VS 2010,参考为: http://msdn .microsoft.com/en-us/library/bb386880(v=VS.100)

来自 MSDN 的示例:

在下面的示例中,Orders 和 BadOrders 都是类型的实体集
Order,并且 Id 被假定为 Order 的单键属性。这
示例说明了我们如何生成对实体的引用
不良订单。请注意,引用可能是悬空的。也就是说,
引用实际上可能无法识别特定实体。在那些情况下,
对该引用执行 DEREF 操作将返回 null。

 select CreateRef(LOB.BadOrders, row(o.Id)) 
from LOB.Orders as o 

使用实体框架SQL的示例代码:

using (EntityConnection conn =
    new EntityConnection("name=AdventureWorksEntities"))
{
    conn.Open();
    // Create a query that takes two parameters.
    string esqlQuery =
        @"SELECT VALUE Contact FROM AdventureWorksEntities.Contact 
                    AS Contact WHERE Contact.LastName = @ln AND
                    Contact.FirstName = @fn";

try
{
    using (EntityCommand cmd = new EntityCommand(esqlQuery, conn))
    {
        // Create two parameters and add them to 
        // the EntityCommand's Parameters collection 
        EntityParameter param1 = new EntityParameter();
        param1.ParameterName = "ln";
        param1.Value = "Adams";
        EntityParameter param2 = new EntityParameter();
        param2.ParameterName = "fn";
        param2.Value = "Frances";

        cmd.Parameters.Add(param1);
        cmd.Parameters.Add(param2);

        using (DbDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
        {
            // Iterate through the collection of Contact items.
            while (rdr.Read())
            {
                Console.WriteLine(rdr["FirstName"]);
                Console.WriteLine(rdr["LastName"]);
            }
        }
    }
}
catch (EntityException ex)
{
    Console.WriteLine(ex.ToString());
}
conn.Close();
}

Entity SQL's CREATEREF reference: http://msdn.microsoft.com/en-us/library/bb386880(v=VS.90)

It's used to "Fabricates references to an entity in an entityset". You can also find references of REF and DEREF from the link.

For VS 2010, the reference is: http://msdn.microsoft.com/en-us/library/bb386880(v=VS.100)

Sample from MSDN:

In the example below, Orders and BadOrders are both entitysets of type
Order, and Id is assumed to be the single key property of Order. The
example illustrates how we may produce a reference to an entity in
BadOrders. Note that the reference may be dangling. That is, the
reference may not actually identify a specific entity. In those cases,
a DEREF operation on that reference returns a null.

 select CreateRef(LOB.BadOrders, row(o.Id)) 
from LOB.Orders as o 

Sample code of using entity framework SQL:

using (EntityConnection conn =
    new EntityConnection("name=AdventureWorksEntities"))
{
    conn.Open();
    // Create a query that takes two parameters.
    string esqlQuery =
        @"SELECT VALUE Contact FROM AdventureWorksEntities.Contact 
                    AS Contact WHERE Contact.LastName = @ln AND
                    Contact.FirstName = @fn";

try
{
    using (EntityCommand cmd = new EntityCommand(esqlQuery, conn))
    {
        // Create two parameters and add them to 
        // the EntityCommand's Parameters collection 
        EntityParameter param1 = new EntityParameter();
        param1.ParameterName = "ln";
        param1.Value = "Adams";
        EntityParameter param2 = new EntityParameter();
        param2.ParameterName = "fn";
        param2.Value = "Frances";

        cmd.Parameters.Add(param1);
        cmd.Parameters.Add(param2);

        using (DbDataReader rdr = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
        {
            // Iterate through the collection of Contact items.
            while (rdr.Read())
            {
                Console.WriteLine(rdr["FirstName"]);
                Console.WriteLine(rdr["LastName"]);
            }
        }
    }
}
catch (EntityException ex)
{
    Console.WriteLine(ex.ToString());
}
conn.Close();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文