开发者

Can someone explain what REF, CREATEREF, DEREF, KEY in Entity SQL do?

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜