gpt4 book ai didi

entity-framework - 有人能解释一下 Entity SQL 中的 REF、CREATEREF、DEREF、KEY 是做什么的吗?

转载 作者:行者123 更新时间:2023-12-03 18:04:27 24 4
gpt4 key购买 nike

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

最佳答案

实体 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 的示例:

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

使用 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();
}

关于entity-framework - 有人能解释一下 Entity SQL 中的 REF、CREATEREF、DEREF、KEY 是做什么的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7611818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com