5

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

Piotr Perak
  • 10,718
  • 9
  • 49
  • 86
  • This is something I am also trying to find out. I can see plenty of pages that talk about how but not why... – J M Mar 04 '12 at 16:02

1 Answers1

-1

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();
}
Eriawan Kusumawardhono
  • 4,796
  • 4
  • 46
  • 49
  • have you satisfied with this answer? please remark this as an answer or if this is not the answer for you, please make comments on this answer. – Eriawan Kusumawardhono Oct 04 '11 at 04:04
  • Well none of the links works. And I wanted to see an example of using those operators and consuming results in C#. Not links to documentation. When should I use those operators and what they give me? – Piotr Perak Oct 06 '11 at 18:22
  • I have corrected the links and add a simple code sample for you. – Eriawan Kusumawardhono Oct 07 '11 at 04:24
  • 1
    Closer ;) But your code does not use REF, CREATEREF, DEREF operators. That's what I'm asking. Why use any of those three when you can do what you did in your example - SELECT VALUE? – Piotr Perak Oct 08 '11 at 05:36
  • You are not fair enough. Your original question is only asking about REF, CREATEREF and DEREF, not asking on other topic such as SELECT VALUE. Please open other question with SELECT VALUE topic you want. – Eriawan Kusumawardhono May 15 '12 at 08:24
  • Yes I'm not asking about SELECT VALUE. So why on earth are you giving me SELECT VALUE examples? What's wrong with you? – Piotr Perak May 15 '12 at 21:34
  • The sample I got is from MSDN. Please check the above link. MSDN itself use SELECT VALUE as its sample. I'm not making this up, @Peri – Eriawan Kusumawardhono May 16 '12 at 07:13
  • Again. I am NOT asking about SELECT VALUE. And the code you included is not from pages you gave links to. I have no idea why you posted this code. It has no relevance to my question! – Piotr Perak May 16 '12 at 20:05