Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

EntityCommand > EntityConnection.CreateCommand()

EntityConnection.CreateCommand()

Alternativ kann ein EntityCommand-Objekt auch ohne Konstruktor mit der CreateCommand()-Methode der EntityConnection-Klasse erzeugt werden. Auf diesem Weg wird mit diesem in einem Aufruf auch die Verbindung (Connection-Eigenschaft) zugewiesen, was so also nicht mehr explizit geschehen muss.

// Verbindung erstellen
using (EntityConnection con = new EntityConnection("Name=TonisTortenTraumEntities;"))
{
    // Abfragetext
    const string eSql = "SELECT COUNT(K.Name) AS Anzahl FROM TonisTortenTraumEntities.Kunden AS K;";

    // EntityCommand-Objekt erstellen
    using (EntityCommand cmd = con.CreateCommand())
    {
        // Abfragetext muss explizit zugewiesen werden
        cmd.CommandText = eSql;

        ...
    }
}

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial