static void Main(string[] args) { using (var c = new EntityConnection("name=AdventureWorksEntities")) { c.StateChange += EStateChange; var cmd = "SELECT VALUE C FROM AdventureWorksEntities.Contatos AS C WHERE C.ContactID=@ContactID"; using (var k = new EntityCommand(cmd, c)) { k.Parameters.AddWithValue("ContactID", 1); c.Open(); var dr = k.ExecuteReader(CommandBehavior.SequentialAccess); if (dr.Read()) //while se existir mais de um registro { Console.WriteLine(dr["Nome"]); } if (c.State != ConnectionState.Closed) c.Close(); } } Console.ReadKey(); }
public void Test1() { string SELECT_PERSONS_ALL = "SELECT p.id as person_id, p.fname, p.lname, ph.id as phone_id , " + "ph.phonevalue as phonevalue, a.id as address_id , a.addressvalue as addressvalue " + "FROM Entities.People as p INNER JOIN Entities.Addresses as a ON a.personid = p.id " + "INNER JOIN Entities.Phones as ph ON ph.personid = p.id"; EntityConnection m_connection = new EntityConnection("name=Entities"); List<Mock.PhoneBook.Phone> list = new List<Mock.PhoneBook.Phone>(); m_connection.Open(); Infrastructure.PhoneBook.IMockConvertor convertor = new ERDBArch.Modules.PhoneBook.BLL.PersonConvertor(); using (EntityCommand cmd = new EntityCommand(SELECT_PERSONS_ALL, m_connection)) { using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { while (reader.Read()) { System.Diagnostics.Debug.WriteLine(reader["person_id"]); } } } m_connection.Close(); }
/// <summary> /// The constructor for the data reader, each EntityDataReader must always be associated with a EntityCommand and an underlying /// DbDataReader. It is expected that EntityDataReader only has a reference to EntityCommand and doesn't assume responsibility /// of cleaning the command object, but it does assume responsibility of cleaning up the store data reader object. /// </summary> internal EntityDataReader(EntityCommand command, DbDataReader storeDataReader, CommandBehavior behavior) { Debug.Assert(command != null && storeDataReader != null); _command = command; _storeDataReader = storeDataReader; _storeExtendedDataRecord = storeDataReader as IExtendedDataRecord; _behavior = behavior; }
internal static void ExecuteESqlQuery(string cxString, string query) { EntityConnection connection = new EntityConnection(cxString); EntityCommand command = new EntityCommand(query, connection); connection.Open(); try { command.ExecuteReader(CommandBehavior.SequentialAccess).Dump<EntityDataReader>(); } finally { connection.Close(); } }
/// <summary> /// Given an entity command, returns the associated entity transaction and performs validation /// to ensure the transaction is consistent. /// </summary> /// <param name="entityCommand">Entity command instance. Must not be null.</param> /// <returns>Entity transaction</returns> internal static EntityTransaction GetEntityTransaction(EntityCommand entityCommand) { Debug.Assert(null != entityCommand); EntityTransaction entityTransaction = (EntityTransaction)entityCommand.Transaction; // Check to make sure that either the command has no transaction associated with it, or it // matches the one used by the connection if (entityTransaction != null && entityTransaction != entityCommand.Connection.CurrentTransaction) { throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.EntityClient_InvalidTransactionForCommand); } // Now we have asserted that EntityCommand either has no transaction or has one that matches the // one used in the connection, we can simply use the connection's transaction object entityTransaction = entityCommand.Connection.CurrentTransaction; return entityTransaction; }
/// <summary> /// Creates a new instance of EntityClientCacheKey given a entityCommand instance /// </summary> /// <param name="entityCommand"></param> internal EntityClientCacheKey(EntityCommand entityCommand) { // Command Type _commandType = entityCommand.CommandType; // Statement _eSqlStatement = entityCommand.CommandText; // Parameters _parametersToken = GetParametersToken(entityCommand); _parameterCount = entityCommand.Parameters.Count; // Hashcode _hashCode = _commandType.GetHashCode() ^ _eSqlStatement.GetHashCode() ^ _parametersToken.GetHashCode(); }
protected int GetEntityCount(string esqlQuery) { int count = 0; using (var connection = new EntityConnection(AboutInheritanceEntitiesConnectionString)) { connection.Open(); using (var command = new EntityCommand(esqlQuery, connection)) { using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { while (reader.Read()) { count = count + 1; } } } } return count; }
public override void ExecuteESqlQuery(IConnectionInfo cxInfo, string query) { EntityConnection connection; object dbContext = base.InstantiateBaseContext(cxInfo); CheckForUnpatchedCx(dbContext); string eSqlCxString = GetESqlCxString(dbContext); EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(eSqlCxString); string str2 = builder["metadata"] as string; if ((str2 != null) && str2.Trim().ToUpperInvariant().StartsWith("READER:")) { connection = new EntityConnection(GetObjectContext(dbContext).MetadataWorkspace, (DbConnection) GetIDbConnection(dbContext)); } else { connection = new EntityConnection(eSqlCxString); } using (connection) { EntityCommand command = new EntityCommand(query, connection); connection.Open(); command.ExecuteReader(CommandBehavior.SequentialAccess).Dump<EntityDataReader>(); } }
/// <summary> /// Получение данных для синхронизации по сущности /// </summary> public global::System.Nullable<decimal> GetLinkSyncServEntData(global::System.Nullable<double> P_LINK_SYNC_SERV_ENT_ID, global::System.Nullable<decimal> P_ITERATOR_NUMBER, ref string P_XML_DATA, ref string P_ERROR_MSG) { if (this.Connection.State != System.Data.ConnectionState.Open) this.Connection.Open(); System.Data.EntityClient.EntityCommand command = new System.Data.EntityClient.EntityCommand(); if (this.CommandTimeout.HasValue) command.CommandTimeout = this.CommandTimeout.Value; command.CommandType = System.Data.CommandType.StoredProcedure; command.CommandText = @"SyncServicesEntities.GET_ENTITY_DATA"; command.Connection = (System.Data.EntityClient.EntityConnection)this.Connection; EntityParameter P_LINK_SYNC_SERV_ENT_IDParameter = new EntityParameter("P_LINK_SYNC_SERV_ENT_ID", System.Data.DbType.Double); if (P_LINK_SYNC_SERV_ENT_ID.HasValue) P_LINK_SYNC_SERV_ENT_IDParameter.Value = P_LINK_SYNC_SERV_ENT_ID; command.Parameters.Add(P_LINK_SYNC_SERV_ENT_IDParameter); EntityParameter P_ITERATOR_NUMBERParameter = new EntityParameter("P_ITERATOR_NUMBER", System.Data.DbType.Decimal); if (P_ITERATOR_NUMBER.HasValue) P_ITERATOR_NUMBERParameter.Value = P_ITERATOR_NUMBER; command.Parameters.Add(P_ITERATOR_NUMBERParameter); EntityParameter P_XML_DATAParameter = new EntityParameter("P_XML_DATA", System.Data.DbType.String); if (P_XML_DATA != null) P_XML_DATAParameter.Value = P_XML_DATA; command.Parameters.Add(P_XML_DATAParameter); EntityParameter P_ERROR_MSGParameter = new EntityParameter("P_ERROR_MSG", System.Data.DbType.String); if (P_ERROR_MSG != null) P_ERROR_MSGParameter.Value = P_ERROR_MSG; command.Parameters.Add(P_ERROR_MSGParameter); global::System.Nullable<decimal> result = (global::System.Nullable<decimal>)command.ExecuteScalar(); if (P_XML_DATAParameter.Value != null && !(P_XML_DATAParameter.Value is System.DBNull)) P_XML_DATA = (string)P_XML_DATAParameter.Value; else P_XML_DATA = string.Empty; if (P_ERROR_MSGParameter.Value != null && !(P_ERROR_MSGParameter.Value is System.DBNull)) P_ERROR_MSG = (string)P_ERROR_MSGParameter.Value; else P_ERROR_MSG = string.Empty; return result; }
/// <summary> /// Internal execute method -- copies command information from the map command /// to the command objects, executes them, and builds the result assembly /// structures needed to return the data reader /// </summary> /// <param name="entityCommand"></param> /// <param name="behavior"></param> /// <returns></returns> /// <exception cref="InvalidOperationException">behavior must specify CommandBehavior.SequentialAccess</exception> /// <exception cref="InvalidOperationException">input parameters in the entityCommand.Parameters collection must have non-null values.</exception> internal DbDataReader Execute(EntityCommand entityCommand, CommandBehavior behavior) { if (CommandBehavior.SequentialAccess != (behavior & CommandBehavior.SequentialAccess)) { throw EntityUtil.MustUseSequentialAccess(); } DbDataReader storeDataReader = ExecuteStoreCommands(entityCommand, behavior); DbDataReader result = null; // If we actually executed something, then go ahead and construct a bridge // data reader for it. if (null != storeDataReader) { try { ColumnMap columnMap = this.CreateColumnMap(storeDataReader, 0); if (null == columnMap) { // For a query with no result type (and therefore no column map), consume the reader. // When the user requests Metadata for this reader, we return nothing. CommandHelper.ConsumeReader(storeDataReader); result = storeDataReader; } else { result = BridgeDataReader.Create(storeDataReader, columnMap, entityCommand.Connection.GetMetadataWorkspace(), GetNextResultColumnMaps(storeDataReader)); } } catch { // dispose of store reader if there is an error creating the BridgeDataReader storeDataReader.Dispose(); throw; } } return result; }
private static void AddComparison(EntityCommand command, StringBuilder segment, string alias, string propertyName, string value) { if (value != null) { if (segment.Length != 0) { segment.Append(" AND "); } segment.Append(alias); segment.Append("."); segment.Append(propertyName); segment.Append(" LIKE @"); string parameterName = "p" + command.Parameters.Count.ToString(CultureInfo.InvariantCulture); segment.Append(parameterName); EntityParameter parameter = new EntityParameter(); parameter.ParameterName = parameterName; parameter.Value = value; command.Parameters.Add(parameter); } }
private static void AddFilterEntry(EntityCommand command, StringBuilder segment, string alias, EntityStoreSchemaFilterEntry entry) { StringBuilder filterText = new StringBuilder(); AddComparison(command, filterText, alias, "CatalogName", entry.Catalog); AddComparison(command, filterText, alias, "SchemaName", entry.Schema); string name = entry.Name; bool allNull = (entry.Catalog == null && entry.Schema == null && entry.Name == null); if (allNull) { name = "%"; } AddComparison(command, filterText, alias, "Name", name); if (segment.Length != 0) { segment.Append(" OR "); } segment.Append("("); segment.Append(filterText); segment.Append(")"); }
public void UserDefinedFunction() { using (EntityConnection conn = new EntityConnection("name=testEntities")) { conn.Open(); string query = @"SELECT e.FirstName AS Name FROM testEntities.Employees AS e WHERE testModel.Store.spFunc(e.Id, '') = 6"; using (EntityCommand cmd = new EntityCommand(query, conn)) { EntityDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); Assert.IsTrue(reader.Read()); Assert.AreEqual("Scooby", reader[0]); } } }
internal virtual EntityDataReader CreateEntityDataReader( EntityCommand entityCommand, DbDataReader storeDataReader, CommandBehavior behavior) { return new EntityDataReader(entityCommand, storeDataReader, behavior); }
/// <summary> /// Returns a string representation of the parameter list /// </summary> /// <param name="entityCommand"></param> /// <returns></returns> private static string GetParametersToken(EntityCommand entityCommand) { if (null == entityCommand.Parameters || 0 == entityCommand.Parameters.Count) { // // means no parameters // return "@@0"; } // Ensure that parameter DbTypes are valid and there are no duplicate names Dictionary<string, TypeUsage> paramTypeUsage = entityCommand.GetParameterTypeUsage(); Debug.Assert(paramTypeUsage.Count == entityCommand.Parameters.Count, "entityParameter collection and query parameter collection must have the same number of entries"); if (1 == paramTypeUsage.Count) { // if its one parameter only, there is no need to use stringbuilder return "@@1:" + entityCommand.Parameters[0].ParameterName + ":" + GetTypeUsageToken(paramTypeUsage[entityCommand.Parameters[0].ParameterName]); } else { StringBuilder sb = new StringBuilder(entityCommand.Parameters.Count * EstimatedParameterStringSize); Debug.Assert(paramTypeUsage.Count == entityCommand.Parameters.Count, "entityParameter collection and query parameter collection must have the same number of entries"); sb.Append("@@"); sb.Append(entityCommand.Parameters.Count); sb.Append(":"); string separator = ""; foreach (KeyValuePair<string, TypeUsage> param in paramTypeUsage) { sb.Append(separator); sb.Append(param.Key); sb.Append(":"); sb.Append(GetTypeUsageToken(param.Value)); separator = ";"; } return sb.ToString(); } }
/// <summary> /// Execute the store commands, and return IteratorSources for each one /// </summary> /// <param name="entityCommand"></param> /// <param name="behavior"></param> internal DbDataReader ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) { // SQLPT #120007433 is the work item to implement MARS support, which we // need to do here, but since the PlanCompiler doesn't // have it yet, neither do we... if (1 != _mappedCommandDefinitions.Count) { throw EntityUtil.NotSupported("MARS"); } EntityTransaction entityTransaction = CommandHelper.GetEntityTransaction(entityCommand); DbCommandDefinition definition = _mappedCommandDefinitions[0]; DbCommand storeProviderCommand = definition.CreateCommand(); CommandHelper.SetStoreProviderCommandState(entityCommand, entityTransaction, storeProviderCommand); // Copy over the values from the map command to the store command; we // assume that they were not renamed by either the plan compiler or SQL // Generation. // // Note that this pretty much presumes that named parameters are supported // by the store provider, but it might work if we don't reorder/reuse // parameters. // // Note also that the store provider may choose to add parameters to thier // command object for some things; we'll only copy over the values for // parameters that we find in the EntityCommands parameters collection, so // we won't damage anything the store provider did. bool hasOutputParameters = false; if (storeProviderCommand.Parameters != null) // SQLBUDT 519066 { DbProviderServices storeProviderServices = DbProviderServices.GetProviderServices(entityCommand.Connection.StoreProviderFactory); foreach (DbParameter storeParameter in storeProviderCommand.Parameters) { // I could just use the string indexer, but then if I didn't find it the // consumer would get some ParameterNotFound exeception message and that // wouldn't be very meaningful. Instead, I use the IndexOf method and // if I don't find it, it's not a big deal (The store provider must // have added it). int parameterOrdinal = entityCommand.Parameters.IndexOf(storeParameter.ParameterName); if (-1 != parameterOrdinal) { EntityParameter entityParameter = entityCommand.Parameters[parameterOrdinal]; SyncParameterProperties(entityParameter, storeParameter, storeProviderServices); if (storeParameter.Direction != ParameterDirection.Input) { hasOutputParameters = true; } } } } // If the EntityCommand has output parameters, we must synchronize parameter values when // the reader is closed. Tell the EntityCommand about the store command so that it knows // where to pull those values from. if (hasOutputParameters) { entityCommand.SetStoreProviderCommand(storeProviderCommand); } DbDataReader reader = null; try { reader = storeProviderCommand.ExecuteReader(behavior & ~CommandBehavior.SequentialAccess); } catch (Exception e) { // we should not be wrapping all exceptions if (EntityUtil.IsCatchableExceptionType(e)) { // we don't wan't folks to have to know all the various types of exceptions that can // occur, so we just rethrow a CommandDefinitionException and make whatever we caught // the inner exception of it. throw EntityUtil.CommandExecution(System.Data.Entity.Strings.EntityClient_CommandDefinitionExecutionFailed, e); } throw; } return(reader); }
/// <summary> /// There are no comments for GET_SYSDATE in the schema. /// </summary> public global::System.Nullable<System.DateTime> GET_SYSDATE () { if (this.Connection.State != System.Data.ConnectionState.Open) this.Connection.Open(); System.Data.EntityClient.EntityCommand command = new System.Data.EntityClient.EntityCommand(); if(this.CommandTimeout.HasValue) command.CommandTimeout = this.CommandTimeout.Value; command.CommandType = System.Data.CommandType.StoredProcedure; command.CommandText = @"SyncServicesEntities.GET_SYSDATE"; command.Connection = (System.Data.EntityClient.EntityConnection)this.Connection; global::System.Nullable<System.DateTime> result = (global::System.Nullable<System.DateTime>)command.ExecuteScalar(); return result; }
/// <summary> /// Execute the store commands, and return IteratorSources for each one /// </summary> /// <param name="entityCommand"></param> /// <param name="behavior"></param> internal DbDataReader ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) { // SQLPT #120007433 is the work item to implement MARS support, which we // need to do here, but since the PlanCompiler doesn't // have it yet, neither do we... if (1 != _mappedCommandDefinitions.Count) { throw EntityUtil.NotSupported("MARS"); } EntityTransaction entityTransaction = CommandHelper.GetEntityTransaction(entityCommand); DbCommandDefinition definition = _mappedCommandDefinitions[0]; DbCommand storeProviderCommand = definition.CreateCommand(); CommandHelper.SetStoreProviderCommandState(entityCommand, entityTransaction, storeProviderCommand); // Copy over the values from the map command to the store command; we // assume that they were not renamed by either the plan compiler or SQL // Generation. // // Note that this pretty much presumes that named parameters are supported // by the store provider, but it might work if we don't reorder/reuse // parameters. // // Note also that the store provider may choose to add parameters to thier // command object for some things; we'll only copy over the values for // parameters that we find in the EntityCommands parameters collection, so // we won't damage anything the store provider did. bool hasOutputParameters = false; if (storeProviderCommand.Parameters != null) // SQLBUDT 519066 { DbProviderServices storeProviderServices = DbProviderServices.GetProviderServices(entityCommand.Connection.StoreProviderFactory); foreach (DbParameter storeParameter in storeProviderCommand.Parameters) { // I could just use the string indexer, but then if I didn't find it the // consumer would get some ParameterNotFound exeception message and that // wouldn't be very meaningful. Instead, I use the IndexOf method and // if I don't find it, it's not a big deal (The store provider must // have added it). int parameterOrdinal = entityCommand.Parameters.IndexOf(storeParameter.ParameterName); if (-1 != parameterOrdinal) { EntityParameter entityParameter = entityCommand.Parameters[parameterOrdinal]; SyncParameterProperties(entityParameter, storeParameter, storeProviderServices); if (storeParameter.Direction != ParameterDirection.Input) { hasOutputParameters = true; } } } } // If the EntityCommand has output parameters, we must synchronize parameter values when // the reader is closed. Tell the EntityCommand about the store command so that it knows // where to pull those values from. if (hasOutputParameters) { entityCommand.SetStoreProviderCommand(storeProviderCommand); } DbDataReader reader = null; try { reader = storeProviderCommand.ExecuteReader(behavior & ~CommandBehavior.SequentialAccess); } catch (Exception e) { // we should not be wrapping all exceptions if (EntityUtil.IsCatchableExceptionType(e)) { // we don't wan't folks to have to know all the various types of exceptions that can // occur, so we just rethrow a CommandDefinitionException and make whatever we caught // the inner exception of it. throw EntityUtil.CommandExecution(System.Data.Entity.Strings.EntityClient_CommandDefinitionExecutionFailed, e); } throw; } return reader; }
public void Verify_querying_database_with_EntityClient_works() { const string commandText = "SELECT C.CompanyName, C.Location FROM NorthwindEntities.Customers AS C WHERE C.CustomerID LIKE @CustomerID"; using (var connection = new EntityConnection(NorthwindEntitiesConnectionString)) { connection.Open(); using (var command = new EntityCommand(commandText, connection)) { command.Parameters.AddWithValue("CustomerID", "A%"); using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { foreach (var expectedResult in expectedResults) { reader.Read(); Assert.Equal(expectedResult.Name, reader["CompanyName"]); Assert.Equal(expectedResult.Location, ((DbGeography)reader["Location"]).AsText()); } Assert.False(reader.Read()); } } } Console.WriteLine(); }
/// <summary> /// There are no comments for SET_LINK_SYNC_SERV_CALL_DATA in the schema. /// </summary> public void SET_LINK_SYNC_SERV_CALL_DATA (global::System.Nullable<decimal> P_LINK_SYNC_SERV_ENT_ID, global::System.Nullable<System.DateTime> P_SYNC_TIME) { if (this.Connection.State != System.Data.ConnectionState.Open) this.Connection.Open(); System.Data.EntityClient.EntityCommand command = new System.Data.EntityClient.EntityCommand(); if(this.CommandTimeout.HasValue) command.CommandTimeout = this.CommandTimeout.Value; command.CommandType = System.Data.CommandType.StoredProcedure; command.CommandText = @"SyncServicesEntities.SET_LINK_SYNC_SERV_CALL_DATA"; command.Connection = (System.Data.EntityClient.EntityConnection)this.Connection; EntityParameter P_LINK_SYNC_SERV_ENT_IDParameter = new EntityParameter("P_LINK_SYNC_SERV_ENT_ID", System.Data.DbType.Decimal); if (P_LINK_SYNC_SERV_ENT_ID.HasValue) P_LINK_SYNC_SERV_ENT_IDParameter.Value = P_LINK_SYNC_SERV_ENT_ID; command.Parameters.Add(P_LINK_SYNC_SERV_ENT_IDParameter); EntityParameter P_SYNC_TIMEParameter = new EntityParameter("P_SYNC_TIME", System.Data.DbType.DateTime); if (P_SYNC_TIME.HasValue) P_SYNC_TIMEParameter.Value = P_SYNC_TIME; command.Parameters.Add(P_SYNC_TIMEParameter); command.ExecuteNonQuery(); }
/// <summary> /// There are no comments for UPDATE_ENTITY_DATA in the schema. /// </summary> public global::System.Nullable<decimal> UPDATE_ENTITY_DATA (string P_IN_XML_DATA, global::System.Nullable<double> P_ELSYS_TYPE_ID, ref string P_ERROR_MSG) { if (this.Connection.State != System.Data.ConnectionState.Open) this.Connection.Open(); System.Data.EntityClient.EntityCommand command = new System.Data.EntityClient.EntityCommand(); if(this.CommandTimeout.HasValue) command.CommandTimeout = this.CommandTimeout.Value; command.CommandType = System.Data.CommandType.StoredProcedure; command.CommandText = @"SyncServicesEntities.UPDATE_ENTITY_DATA"; command.Connection = (System.Data.EntityClient.EntityConnection)this.Connection; EntityParameter P_IN_XML_DATAParameter = new EntityParameter("P_IN_XML_DATA", System.Data.DbType.String); if (P_IN_XML_DATA != null) P_IN_XML_DATAParameter.Value = P_IN_XML_DATA; command.Parameters.Add(P_IN_XML_DATAParameter); EntityParameter P_ELSYS_TYPE_IDParameter = new EntityParameter("P_ELSYS_TYPE_ID", System.Data.DbType.Double); if (P_ELSYS_TYPE_ID.HasValue) P_ELSYS_TYPE_IDParameter.Value = P_ELSYS_TYPE_ID; command.Parameters.Add(P_ELSYS_TYPE_IDParameter); EntityParameter P_ERROR_MSGParameter = new EntityParameter("P_ERROR_MSG", System.Data.DbType.String); if (P_ERROR_MSG != null) P_ERROR_MSGParameter.Value = P_ERROR_MSG; command.Parameters.Add(P_ERROR_MSGParameter); global::System.Nullable<decimal> result = (global::System.Nullable<decimal>)command.ExecuteScalar(); if (P_ERROR_MSGParameter.Value != null && !(P_ERROR_MSGParameter.Value is System.DBNull)) P_ERROR_MSG = (string)P_ERROR_MSGParameter.Value; else P_ERROR_MSG = default(string); return result; }
/// <summary> /// Given an entity command, store provider command and a connection, sets all output parameter values on the entity command. /// The connection is used to determine how to map spatial values. /// </summary> /// <param name="entityCommand">Entity command on which to set parameter values. Must not be null.</param> /// <param name="storeProviderCommand">Store provider command from which to retrieve parameter values. Must not /// be null.</param> /// <param name="connection">The connection on which the command was run. Must not be null</param> internal static void SetEntityParameterValues(EntityCommand entityCommand, DbCommand storeProviderCommand, EntityConnection connection) { Debug.Assert(null != entityCommand); Debug.Assert(null != storeProviderCommand); Debug.Assert(null != connection); foreach (DbParameter storeParameter in storeProviderCommand.Parameters) { ParameterDirection direction = storeParameter.Direction; if (0 != (direction & ParameterDirection.Output)) { // if the entity command also defines the parameter, propagate store parameter value // to entity parameter int parameterOrdinal = entityCommand.Parameters.IndexOf(storeParameter.ParameterName); if (0 <= parameterOrdinal) { EntityParameter entityParameter = entityCommand.Parameters[parameterOrdinal]; object parameterValue = storeParameter.Value; TypeUsage parameterType = entityParameter.GetTypeUsage(); if (Helper.IsSpatialType(parameterType)) { parameterValue = GetSpatialValueFromProviderValue(parameterValue, (PrimitiveType)parameterType.EdmType, connection); } entityParameter.Value = parameterValue; } } } }
/// <summary> /// Sectes all Phones from person table into List /// </summary> /// <returns>List of Phone mocks</returns> protected List<Mock.PhoneBook.Phone> GetPhones() { List<Mock.PhoneBook.Phone> list = new List<Mock.PhoneBook.Phone>(); m_connection.Open(); Infrastructure.PhoneBook.IMockConvertor convertor = new BLL.PhoneConvertor(); using (EntityCommand cmd = new EntityCommand(SELECT_PHONES_ALL, m_connection)) { using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { while (reader.Read()) { list.Add(convertor.ToObject(Enumerable.Range(0, reader.FieldCount).ToDictionary(reader.GetName, reader.GetValue)) as Mock.PhoneBook.Phone); } } } m_connection.Close(); return list; }
/// <summary> /// Given an entity command and entity transaction, passes through relevant state to store provider /// command. /// </summary> /// <param name="entityCommand">Entity command. Must not be null.</param> /// <param name="entityTransaction">Entity transaction. Must not be null.</param> /// <param name="storeProviderCommand">Store provider command that is being setup. Must not be null.</param> internal static void SetStoreProviderCommandState(EntityCommand entityCommand, EntityTransaction entityTransaction, DbCommand storeProviderCommand) { Debug.Assert(null != entityCommand); Debug.Assert(null != storeProviderCommand); storeProviderCommand.CommandTimeout = entityCommand.CommandTimeout; storeProviderCommand.Connection = ((EntityConnection)entityCommand.Connection).StoreConnection; storeProviderCommand.Transaction = (null != entityTransaction) ? entityTransaction.StoreTransaction : null; storeProviderCommand.UpdatedRowSource = entityCommand.UpdatedRowSource; }
/// <summary> /// Gets all Persons form DB with JOIN /// </summary> /// <returns>List of Person</returns> public List<Model.Person> GetPersonsJoin() { List<Model.Person> res = new List<Model.Person>(); m_connection.Open(); Infrastructure.PhoneBook.IMockConvertor convertor = new BLL.PersonConvertor(); using (EntityCommand cmd = new EntityCommand(SELECT_PERSONS_ALL, m_connection)) { using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { while (reader.Read()) { Dictionary<string, object> dic = Enumerable.Range(0, reader.FieldCount).ToDictionary(reader.GetName, reader.GetValue); Mock.PhoneBook.Person person = new BLL.PersonConvertor().ToObject(dic) as Mock.PhoneBook.Person; if (person.ID == 0) person = Mock.PhoneBook.Person.Null; Mock.PhoneBook.Phone phone = new BLL.PhoneConvertor().ToObject(dic) as Mock.PhoneBook.Phone; if (phone.ID == 0) person = Mock.PhoneBook.Person.Null; Mock.PhoneBook.Address address = new BLL.AddressConvertor().ToObject(dic) as Mock.PhoneBook.Address; if (address.ID == 0) person = Mock.PhoneBook.Person.Null; res.Add(new Model.Person(person, phone, address)); } } } m_connection.Close(); return res; }
/// <summary> /// Close this data reader /// </summary> public override void Close() { if (this._command != null) { this._storeDataReader.Close(); // Notify the command object that we are closing, so clean up operations such as copying output parameters can be done this._command.NotifyDataReaderClosing(); if ((this._behavior & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection) { Debug.Assert(this._command.Connection != null); this._command.Connection.Close(); } this._command = null; } }
internal virtual void InvokeOnDataReaderClosingEvent(EntityCommand sender, EventArgs e) { OnDataReaderClosing(sender, e); }