コード例 #1
0
        /// <summary>
        /// Add a EntityParameter with the given name and value to the collection
        /// </summary>
        /// <param name="parameterName">The name of the parameter to add</param>
        /// <param name="value">The value of the parameter to add</param>
        /// <returns>The index of the new parameter within the collection</returns>
        public EntityParameter AddWithValue(string parameterName, object value)
        {
            EntityParameter param = new EntityParameter();

            param.ParameterName = parameterName;
            param.Value         = value;
            return(this.Add(param));
        }
コード例 #2
0
        public void Delete(int widgetId)
        {
            FlushWidgetCache(widgetId);

            var param = new EntityParameter("WidgetId", System.Data.DbType.Int32);
            param.Value = widgetId;
            _database.ExecuteFunction("DeleteWidgetCascade", param);
            //_database.Delete<Widget>(new Widget { ID = widgetId });
        }
コード例 #3
0
ファイル: EntityParameter.cs プロジェクト: dox0/DotNet471RS3
        /// <summary>
        /// Clones this parameter object
        /// </summary>
        /// <returns>The new cloned object</returns>
        private void CloneHelper(EntityParameter destination)
        {
            CloneHelperCore(destination);

            destination._parameterName = _parameterName;
            destination._dbType        = _dbType;
            destination._edmType       = _edmType;
            destination._precision     = _precision;
            destination._scale         = _scale;
        }
        private void RemoveIndex(int index)
        {
            List <EntityParameter> items = InnerList;

            Debug.Assert((null != items) && (0 <= index) && (index < Count), "RemoveIndex, invalid");
            EntityParameter item = items[index];

            items.RemoveAt(index);
            item.ResetParent();
        }
コード例 #5
0
        private EntityParameter(EntityParameter source) : this() { 
            EntityUtil.CheckArgumentNull(source, "source");

            source.CloneHelper(this);

            ICloneable cloneable = (_value as ICloneable);
            if (null != cloneable) { 
                _value = cloneable.Clone();
            }
        }
コード例 #6
0
        private void CloneHelperCore(EntityParameter destination)
        {
            destination._value = _value;

            destination._direction = _direction;
            destination._size      = _size;

            destination._sourceColumn            = _sourceColumn;
            destination._sourceVersion           = _sourceVersion;
            destination._sourceColumnNullMapping = _sourceColumnNullMapping;
            destination._isNullable = _isNullable;
        }
        private void Replace(int index, object newValue)
        {
            List <EntityParameter> items = InnerList;

            Debug.Assert((null != items) && (0 <= index) && (index < Count), "Replace Index invalid");
            ValidateType(newValue);
            Validate(index, newValue);
            EntityParameter item = items[index];

            items[index] = (EntityParameter)newValue;
            item.ResetParent();
        }
コード例 #8
0
        /// <summary>
        /// Constructs a EntityParameter from a CQT parameter.
        /// </summary>
        /// <param name="queryParameter"></param>
        /// <returns></returns>
        private static EntityParameter CreateEntityParameterFromQueryParameter(KeyValuePair <string, TypeUsage> queryParameter)
        {
            // We really can't have a parameter here that isn't a scalar type...
            Debug.Assert(TypeSemantics.IsScalarType(queryParameter.Value), "Non-scalar type used as query parameter type");

            EntityParameter result = new EntityParameter();

            result.ParameterName = queryParameter.Key;

            EntityCommandDefinition.PopulateParameterFromTypeUsage(result, queryParameter.Value, isOutParam: false);

            return(result);
        }
コード例 #9
0
        private EntityParameter(EntityParameter source) : this()
        {
            EntityUtil.CheckArgumentNull(source, "source");

            source.CloneHelper(this);

            ICloneable cloneable = (_value as ICloneable);

            if (null != cloneable)
            {
                _value = cloneable.Clone();
            }
        }
コード例 #10
0
        internal static void PopulateParameterFromTypeUsage(EntityParameter parameter, TypeUsage type, bool isOutParam)
        {
            // type can be null here if the type provided by the user is not a known model type
            if (type != null)
            {
                PrimitiveTypeKind primitiveTypeKind;

                if (Helper.IsEnumType(type.EdmType))
                {
                    type = TypeUsage.Create(Helper.GetUnderlyingEdmTypeForEnumType(type.EdmType));
                }
                else if (Helper.IsSpatialType(type, out primitiveTypeKind))
                {
                    parameter.EdmType = EdmProviderManifest.Instance.GetPrimitiveType(primitiveTypeKind);
                }
            }

            DbCommandDefinition.PopulateParameterFromTypeUsage(parameter, type, isOutParam);
        }
コード例 #11
0
        /// <summary>
        /// Updates storeParameter size, precision and scale properties from user provided parameter properties.
        /// </summary>
        /// <param name="entityParameter"></param>
        /// <param name="storeParameter"></param>
        private static void SyncParameterProperties(EntityParameter entityParameter, DbParameter storeParameter, DbProviderServices storeProviderServices)
        {
            IDbDataParameter dbDataParameter = (IDbDataParameter)storeParameter;

            // DBType is not currently syncable; it's part of the cache key anyway; this is because we can't guarantee
            // that the store provider will honor it -- (SqlClient doesn't...)
            //if (entityParameter.IsDbTypeSpecified)
            //{
            //    storeParameter.DbType = entityParameter.DbType;
            //}

            // Give the store provider the opportunity to set the value before any parameter state has been copied from
            // the EntityParameter.
            TypeUsage parameterTypeUsage = TypeHelpers.GetPrimitiveTypeUsageForScalar(entityParameter.GetTypeUsage());

            storeProviderServices.SetParameterValue(storeParameter, parameterTypeUsage, entityParameter.Value);

            // Override the store provider parameter state with any explicitly specified values from the EntityParameter.
            if (entityParameter.IsDirectionSpecified)
            {
                storeParameter.Direction = entityParameter.Direction;
            }
            if (entityParameter.IsIsNullableSpecified)
            {
                storeParameter.IsNullable = entityParameter.IsNullable;
            }
            if (entityParameter.IsSizeSpecified)
            {
                storeParameter.Size = entityParameter.Size;
            }
            if (entityParameter.IsPrecisionSpecified)
            {
                dbDataParameter.Precision = entityParameter.Precision;
            }
            if (entityParameter.IsScaleSpecified)
            {
                dbDataParameter.Scale = entityParameter.Scale;
            }
        }
コード例 #12
0
 /// <summary>
 /// Remove a EntityParameter with the given value from the collection
 /// </summary>
 /// <param name="value">The parameter to remove</param>
 public void Remove(EntityParameter value)
 {
     this.Remove((object)value);
 }    
コード例 #13
0
 /// <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;
 }
コード例 #14
0
        public Album[] GetNewestAlbums(int limit)
        {
            Album[] albums = null;

            StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("SELECT i.InterpretID, i.Interpret, i.Interpret_Lang ,a.TitelID, a.Titel1, a.Guid as AlbumId FROM tunesEntities.titel AS a");
            stringBuilder.Append(" INNER JOIN tunesEntities.interpreten AS i ON a.InterpretID = i.InterpretID");
            stringBuilder.Append(" ORDER BY a.TitelID DESC");
            stringBuilder.Append(" LIMIT @limit ");

            string sql = stringBuilder.ToString();

            using (System.Data.EntityClient.EntityConnection entityConnection =
                new System.Data.EntityClient.EntityConnection(this.ConnectionString))
            {
                try
                {
                    entityConnection.Open();
                    using (EntityCommand entityCommand = entityConnection.CreateCommand())
                    {
                        EntityParameter limitParam = new EntityParameter();
                        limitParam.ParameterName = "limit";
                        limitParam.Value = limit;
                        entityCommand.Parameters.Add(limitParam);

                        List<Album> albumCollection = null;
                        entityCommand.CommandText = sql;
                        // Execute the command.
                        using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                        {
                            // Start reading results.
                            while (dataReader.Read())
                            {
                                if (albumCollection == null)
                                {
                                    albumCollection = new List<Album>();
                                }
                                Album album = new Album
                                {
                                    Artist = new Artist
                                    {
                                        Id = dataReader.GetInt32("InterpretID", false, 0),
                                        Name = dataReader.GetString("Interpret", false, string.Empty),
                                        SortName = dataReader.GetString("Interpret_Lang", true, string.Empty)
                                    },
                                    Id = dataReader.GetInt32("TitelID", false, 0),
                                    Title = dataReader.GetString("Titel1", false, string.Empty),
									AlbumId = dataReader.GetGuid("AlbumId", false, Guid.Empty)
                                };
                                albumCollection.Add(album);
                            }
                        }
                        if (albumCollection != null)
                        {
                            albums = albumCollection.ToArray();
                        }
                    }
                }
                finally
                {
                    entityConnection.Close();
                }
            }
            return albums;
        }
コード例 #15
0
        private void GetAlbumTracksByTitelId(Album album, System.Data.EntityClient.EntityConnection entityConnection)
        {
            if (album != null)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT t.LiedID, t.Track, t.Lied ,t.Dauer");
                stringBuilder.Append(" FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" WHERE t.titelid = @albumId");
                stringBuilder.Append(" AND t.Liedpfad IS NOT NULL");
                stringBuilder.Append(" ORDER BY t.Track");
                string sql = stringBuilder.ToString();

                using (EntityCommand entityCommand = entityConnection.CreateCommand())
                {
                    EntityParameter id = new EntityParameter();
                    id.ParameterName = "albumid";
                    id.Value = album.Id;
                    entityCommand.Parameters.Add(id);
                    entityCommand.CommandText = sql;

                    List<Track> tracks = null;
                    using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                    {
                        while (dataReader.Read())
                        {
                            if (tracks == null)
                            {
                                tracks = new List<Track>();
                            }
                            Track track = new Track
                            {
                                Id = dataReader.GetInt32("LiedID", false, 0),
                                TrackNumber = dataReader.GetInt32("Track", false, 0),
                                Name = dataReader.GetString("Lied", false, string.Empty),
                                Duration = dataReader.GetTimeSpan("Dauer", true, TimeSpan.MinValue)
                            };
                            tracks.Add(track);
                        }
                        if (tracks != null)
                        {
                            album.Tracks = tracks.ToArray();
                        }
                    }
                }
            }
        }
コード例 #16
0
        private EntityParameter(EntityParameter source)
            : this()
        {
            //Contract.Requires(source != null);

            source.CloneHelper(this);

            var cloneable = (_value as ICloneable);
            if (null != cloneable)
            {
                _value = cloneable.Clone();
            }
        }
コード例 #17
0
        internal static void PopulateParameterFromTypeUsage(EntityParameter parameter, TypeUsage type, bool isOutParam)
        {
            // type can be null here if the type provided by the user is not a known model type
            if (type != null)
            {
                PrimitiveTypeKind primitiveTypeKind;

                if (Helper.IsEnumType(type.EdmType))
                {
                    type = TypeUsage.Create(Helper.GetUnderlyingEdmTypeForEnumType(type.EdmType));
                }
                else if (Helper.IsSpatialType(type, out primitiveTypeKind))
                {
                    parameter.EdmType = EdmProviderManifest.Instance.GetPrimitiveType(primitiveTypeKind);
                }
            }
            
            DbCommandDefinition.PopulateParameterFromTypeUsage(parameter, type, isOutParam);            
        }
コード例 #18
0
        /// <summary>
        /// Clones this parameter object
        /// </summary>
        /// <returns>The new cloned object</returns>
        private void CloneHelper(EntityParameter destination)
        {
            destination._value = _value;

            destination._direction = _direction;
            destination._size = _size;

            destination._sourceColumn = _sourceColumn;
            destination._sourceVersion = _sourceVersion;
            destination._sourceColumnNullMapping = _sourceColumnNullMapping;
            destination._isNullable = _isNullable;

            destination._parameterName = _parameterName;
            destination._dbType = _dbType;
            destination._edmType = _edmType;
            destination._precision = _precision;
            destination._scale = _scale;
        }
        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);
            }
        }
コード例 #20
0
 /// <summary>
 /// Add a EntityParameter to the collection
 /// </summary>
 /// <param name="value">The parameter to add to the collection</param>
 /// <returns>The index of the new parameter within the collection</returns>
 public EntityParameter Add(EntityParameter value)
 {
     this.Add((object)value);
     return(value);
 }
コード例 #21
0
 /// <summary>
 /// Remove a EntityParameter with the given value from the collection
 /// </summary>
 /// <param name="value">The parameter to remove</param>
 public void Remove(EntityParameter value)
 {
     this.Remove((object)value);
 }
コード例 #22
0
 /// <summary>
 /// Add a EntityParameter with the given value to the collection at a location indicated by the index
 /// </summary>
 /// <param name="index">The index at which the parameter is to be inserted</param>
 /// <param name="value">The value of the parameter</param>
 public void Insert(int index, EntityParameter value)
 {
     this.Insert(index, (object)value);
 }
コード例 #23
0
 /// <summary>
 /// Finds the index in the collection of the given parameter object
 /// </summary>
 /// <param name="value">The parameter to search for</param>
 /// <returns>The index of the parameter, -1 if not found</returns>
 public int IndexOf(EntityParameter value)
 {
     return(IndexOf((object)value));
 }
コード例 #24
0
        /// <summary>
        /// don't let this be constructed publicly;
        /// </summary>
        /// <exception cref="EntityCommandCompilationException">Cannot prepare the command definition for execution; consult the InnerException for more information.</exception>
        /// <exception cref="NotSupportedException">The ADO.NET Data Provider you are using does not support CommandTrees.</exception>
        internal EntityCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
        {
            EntityUtil.CheckArgumentNull(storeProviderFactory, "storeProviderFactory");
            EntityUtil.CheckArgumentNull(commandTree, "commandTree");

            DbProviderServices storeProviderServices = DbProviderServices.GetProviderServices(storeProviderFactory);

            try {
                if (DbCommandTreeKind.Query == commandTree.CommandTreeKind)
                {
                    // Next compile the plan for the command tree
                    List <ProviderCommandInfo> mappedCommandList = new List <ProviderCommandInfo>();
                    ColumnMap columnMap;
                    int       columnCount;
                    PlanCompiler.Compile(commandTree, out mappedCommandList, out columnMap, out columnCount, out _entitySets);
                    _columnMapGenerators = new IColumnMapGenerator[] { new ConstantColumnMapGenerator(columnMap, columnCount) };
                    // Note: we presume that the first item in the ProviderCommandInfo is the root node;
                    Debug.Assert(mappedCommandList.Count > 0, "empty providerCommandInfo collection and no exception?"); // this shouldn't ever happen.

                    // Then, generate the store commands from the resulting command tree(s)
                    _mappedCommandDefinitions = new List <DbCommandDefinition>(mappedCommandList.Count);

                    foreach (ProviderCommandInfo providerCommandInfo in mappedCommandList)
                    {
                        DbCommandDefinition providerCommandDefinition = storeProviderServices.CreateCommandDefinition(providerCommandInfo.CommandTree);

                        if (null == providerCommandDefinition)
                        {
                            throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.ProviderReturnedNullForCreateCommandDefinition);
                        }
                        _mappedCommandDefinitions.Add(providerCommandDefinition);
                    }
                }
                else
                {
                    Debug.Assert(DbCommandTreeKind.Function == commandTree.CommandTreeKind, "only query and function command trees are supported");
                    DbFunctionCommandTree entityCommandTree = (DbFunctionCommandTree)commandTree;

                    // Retrieve mapping and metadata information for the function import.
                    FunctionImportMappingNonComposable mapping          = GetTargetFunctionMapping(entityCommandTree);
                    IList <FunctionParameter>          returnParameters = entityCommandTree.EdmFunction.ReturnParameters;
                    int resultSetCount = returnParameters.Count > 1 ? returnParameters.Count : 1;
                    _columnMapGenerators = new IColumnMapGenerator[resultSetCount];
                    TypeUsage storeResultType = DetermineStoreResultType(entityCommandTree.MetadataWorkspace, mapping, 0, out _columnMapGenerators[0]);
                    for (int i = 1; i < resultSetCount; i++)
                    {
                        DetermineStoreResultType(entityCommandTree.MetadataWorkspace, mapping, i, out _columnMapGenerators[i]);
                    }
                    // Copy over parameters (this happens through a more indirect route in the plan compiler, but
                    // it happens nonetheless)
                    List <KeyValuePair <string, TypeUsage> > providerParameters = new List <KeyValuePair <string, TypeUsage> >();
                    foreach (KeyValuePair <string, TypeUsage> parameter in entityCommandTree.Parameters)
                    {
                        providerParameters.Add(parameter);
                    }

                    // Construct store command tree usage.
                    DbFunctionCommandTree providerCommandTree = new DbFunctionCommandTree(entityCommandTree.MetadataWorkspace, DataSpace.SSpace,
                                                                                          mapping.TargetFunction, storeResultType, providerParameters);

                    DbCommandDefinition storeCommandDefinition = storeProviderServices.CreateCommandDefinition(providerCommandTree);
                    _mappedCommandDefinitions = new List <DbCommandDefinition>(1)
                    {
                        storeCommandDefinition
                    };

                    EntitySet firstResultEntitySet = mapping.FunctionImport.EntitySets.FirstOrDefault();
                    if (firstResultEntitySet != null)
                    {
                        _entitySets = new Set <EntitySet>();
                        _entitySets.Add(mapping.FunctionImport.EntitySets.FirstOrDefault());
                        _entitySets.MakeReadOnly();
                    }
                }

                // Finally, build a list of the parameters that the resulting command should have;
                List <EntityParameter> parameterList = new List <EntityParameter>();

                foreach (KeyValuePair <string, TypeUsage> queryParameter in commandTree.Parameters)
                {
                    EntityParameter parameter = CreateEntityParameterFromQueryParameter(queryParameter);
                    parameterList.Add(parameter);
                }

                _parameters = new System.Collections.ObjectModel.ReadOnlyCollection <EntityParameter>(parameterList);
            }
            catch (EntityCommandCompilationException) {
                // No need to re-wrap EntityCommandCompilationException
                throw;
            }
            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.CommandCompilation(System.Data.Entity.Strings.EntityClient_CommandDefinitionPreparationFailed, e);
                }
                throw;
            }
        }
コード例 #25
0
 /// <summary>
 /// Add a EntityParameter to the collection
 /// </summary>
 /// <param name="value">The parameter to add to the collection</param>
 /// <returns>The index of the new parameter within the collection</returns>
 public EntityParameter Add(EntityParameter value)
 {
     this.Add((object)value);
     return value;
 }
コード例 #26
0
		public CoverImage GetImage(Guid imageId, bool asThumbnail = false)
		{
			CoverImage image = null;

			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("SELECT a.{0}, a.PictureFormat, a.ErstellDatum, a.MutationDatum");
			stringBuilder.Append(" FROM tunesEntities.titel AS a");
			stringBuilder.Append(" WHERE a.guid = @imageId");

			string field = asThumbnail ? "thumbnail" : "cover";
			string sql = string.Format(CultureInfo.InvariantCulture, stringBuilder.ToString(), field);

			using (System.Data.EntityClient.EntityConnection entityConnection =
					new System.Data.EntityClient.EntityConnection(this.ConnectionString))
			{
				try
				{
					entityConnection.Open();
					using (EntityCommand entityCommand = entityConnection.CreateCommand())
					{
						EntityParameter id = new EntityParameter();
						id.ParameterName = "imageId";
						id.Value = imageId.ToString();
						entityCommand.Parameters.Add(id);
						entityCommand.CommandText = sql;
						using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
						{
							if (dataReader.Read())
							{
								image = new CoverImage
								{
									Cover = dataReader.GetBytes(field, true, null),
									Extension = dataReader.GetString("PictureFormat", true,String.Empty),
									ModifiedSince = dataReader.GetDateTime("MutationDatum", true, DateTime.MinValue)
								};
							}
						}
					}
				}
				finally
				{
					entityConnection.Close();
				}
			}
			return image;
		}
コード例 #27
0
        public Track GetTrackById(int trackId)
        {
            Track track = null;
            string audioDirectory = this.AudioDirectory;
            if (string.IsNullOrEmpty(audioDirectory) == false)
            {
                StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("SELECT t.LiedID, t.Track, t.Lied ,t.Dauer, t.Liedpfad, t.guid, a.TitelID, a.Titel1, a.Guid as AlbumId, i.Interpret FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" JOIN tunesEntities.titel AS a ON a.TitelID = t.TitelID");
                stringBuilder.Append(" JOIN tunesEntities.interpreten AS i ON a.InterpretID = i.InterpretID");
                stringBuilder.Append(" WHERE t.LiedId = @trackid");

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                        new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter trackIdParam = new EntityParameter();
                            trackIdParam.ParameterName = "trackid";
                            trackIdParam.Value = trackId;
                            entityCommand.Parameters.Add(trackIdParam);

                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                if (dataReader.Read() == true)
                                {
									track = new Track
									{
										Id = dataReader.GetInt32("LiedID", false, 0),
										TrackNumber = dataReader.GetInt32("Track", false, 0),
										Name = dataReader.GetString("Lied", false, string.Empty),
										Duration = dataReader.GetTimeSpan("Dauer", true, TimeSpan.MinValue),
										Guid = dataReader.GetGuid("guid", false, Guid.Empty),
										Album = new Album
										{
											Id = dataReader.GetInt32("TitelID", false, 0),
											Title = dataReader.GetString("Titel1", false, string.Empty),
											AlbumId = dataReader.GetGuid("AlbumId", false, Guid.Empty),
											Artist = new Artist
											{
												Name = dataReader.GetString("Interpret", false, string.Empty)
											}
										}
									};
                                }
                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return track;
        }
コード例 #28
0
        /// <summary>
        /// Constructs a EntityParameter from a CQT parameter.
        /// </summary>
        /// <param name="queryParameter"></param>
        /// <returns></returns>
        private static EntityParameter CreateEntityParameterFromQueryParameter(KeyValuePair<string, TypeUsage> queryParameter) {
            // We really can't have a parameter here that isn't a scalar type...
            Debug.Assert(TypeSemantics.IsScalarType(queryParameter.Value), "Non-scalar type used as query parameter type");

            EntityParameter result = new EntityParameter();
            result.ParameterName = queryParameter.Key;

            EntityCommandDefinition.PopulateParameterFromTypeUsage(result, queryParameter.Value, isOutParam: false);

            return result;
        }
コード例 #29
0
        public Playlist GetPlaylistById(int playlistId, string userName)
        {
            Playlist playlist = null;
            if (string.IsNullOrEmpty(userName) == false)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT p.ListId, p.ListName, p.User, p.Guid, pe.EntryId, pe.sortorder, pe.Guid as EntryGuid, t.LiedID, t.Lied, t.Dauer, a.Guid as AlbumId, i.Interpret FROM tunesEntities.playlist AS p");
                stringBuilder.Append(" LEFT JOIN tunesEntities.playlistentries AS pe ON p.ListId = pe.PlaylistId");
                stringBuilder.Append(" LEFT JOIN tunesEntities.lieder AS t ON pe.LiedId = t.LiedID");
                stringBuilder.Append(" LEFT JOIN tunesEntities.titel AS a ON t.TitelID = a.TitelID");
                stringBuilder.Append(" LEFT JOIN tunesEntities.interpreten AS i ON a.InterpretID = i.InterpretID");
                stringBuilder.Append(" WHERE p.ListId = @playlistId");
                stringBuilder.Append(" AND p.User = @userName");

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                        new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter trackIdParam = new EntityParameter();
                            trackIdParam.ParameterName = "playlistId";
                            trackIdParam.Value = playlistId;
                            entityCommand.Parameters.Add(trackIdParam);

                            EntityParameter user = new EntityParameter();
                            user.ParameterName = "userName";
                            user.Value = userName;
                            entityCommand.Parameters.Add(user);

                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                // Start reading results.
                                while (dataReader.Read())
                                {
                                    if (playlist == null)
                                    {
                                        playlist = new Playlist
                                        {
                                            Id = dataReader.GetInt32("ListId", false, 0),
                                            Name = dataReader.GetString("ListName", false, string.Empty),
                                            UserName = dataReader.GetString("User", false, string.Empty),
											Guid = dataReader.GetGuid("Guid", false, Guid.Empty),
                                        };
                                    }
                                    int entryId = dataReader.GetInt32("EntryId", true, 0);
                                    if (entryId > 0)
                                    {
                                        PlaylistEntry entry = new PlaylistEntry
                                        {
                                            Id = entryId,
                                            SortOrder = dataReader.GetInt32("sortorder", true, 0),
											Guid = dataReader.GetGuid("EntryGuid", true, Guid.Empty),
											TrackId = dataReader.GetInt32("LiedID", true, 0),
                                            Name = dataReader.GetString("Lied", true, string.Empty),
                                            Duration = dataReader.GetTimeSpan("Dauer", true, TimeSpan.MinValue),
											AlbumId = dataReader.GetGuid("AlbumId", false, Guid.Empty),
											Artist = dataReader.GetString("Interpret", true, string.Empty)
                                        };
                                        playlist.Entries.Add(entry);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return playlist;
        }
コード例 #30
0
        /// <summary>
        /// Updates storeParameter size, precision and scale properties from user provided parameter properties.
        /// </summary>
        /// <param name="entityParameter"></param>
        /// <param name="storeParameter"></param>
        private static void SyncParameterProperties(EntityParameter entityParameter, DbParameter storeParameter, DbProviderServices storeProviderServices) {
            IDbDataParameter dbDataParameter = (IDbDataParameter)storeParameter;

            // DBType is not currently syncable; it's part of the cache key anyway; this is because we can't guarantee
            // that the store provider will honor it -- (SqlClient doesn't...)
            //if (entityParameter.IsDbTypeSpecified)
            //{
            //    storeParameter.DbType = entityParameter.DbType;
            //}

            // Give the store provider the opportunity to set the value before any parameter state has been copied from
            // the EntityParameter.
            TypeUsage parameterTypeUsage = TypeHelpers.GetPrimitiveTypeUsageForScalar(entityParameter.GetTypeUsage());
            storeProviderServices.SetParameterValue(storeParameter, parameterTypeUsage, entityParameter.Value);

            // Override the store provider parameter state with any explicitly specified values from the EntityParameter.
            if (entityParameter.IsDirectionSpecified)
            {
                storeParameter.Direction = entityParameter.Direction;
            }
            if (entityParameter.IsIsNullableSpecified)
            {
                storeParameter.IsNullable = entityParameter.IsNullable;
            }
            if (entityParameter.IsSizeSpecified)
            {
                storeParameter.Size = entityParameter.Size;
            }
            if (entityParameter.IsPrecisionSpecified)
            {
                dbDataParameter.Precision = entityParameter.Precision;
            }
            if (entityParameter.IsScaleSpecified)
            {
                dbDataParameter.Scale = entityParameter.Scale;
            }
        }
コード例 #31
0
        private void CloneHelperCore(EntityParameter destination) {
            destination._value                     = _value;
            
            destination._direction                 = _direction;
            destination._size                      = _size;

            destination._sourceColumn              = _sourceColumn;
            destination._sourceVersion             = _sourceVersion;
            destination._sourceColumnNullMapping   = _sourceColumnNullMapping;
            destination._isNullable                = _isNullable;
        }
コード例 #32
0
        public Playlist GetPlaylistByIdWithNumberOfEntries(int playlistId, string userName)
        {
            Playlist playlist = null;
            if (string.IsNullOrEmpty(userName) == false)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT p.ListId, p.ListName, p.guid, COUNT(pe.PlaylistId) as Number ");
				stringBuilder.Append(" FROM tunesEntities.playlist AS p");
                stringBuilder.Append(" LEFT JOIN tunesEntities.playlistentries AS pe ON p.ListId = pe.PlaylistId");
                stringBuilder.Append(" WHERE p.ListId = @playlistId");
                stringBuilder.Append(" AND p.User = @userName");
				stringBuilder.Append(" GROUP BY p.listid, p.ListName, p.guid");

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                        new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter id = new EntityParameter();
                            id.ParameterName = "playlistId";
                            id.Value = playlistId;
                            entityCommand.Parameters.Add(id);

                            EntityParameter user = new EntityParameter();
                            user.ParameterName = "userName";
                            user.Value = userName;
                            entityCommand.Parameters.Add(user);

                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                if (dataReader.Read() == true)
                                {
                                    playlist = new Playlist
                                    {
                                        Id = dataReader.GetInt32("ListId", false, 0),
                                        Name = dataReader.GetString("ListName", false, string.Empty),
										Guid = dataReader.GetGuid("guid", false, Guid.Empty),
										NumberEntries = dataReader.GetInt32("Number", false, 0)
                                    };
                                }
                            }
                        }
                    }
						catch(Exception ex)
					{
					}
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return playlist;
        }
コード例 #33
0
        /// <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);
        }
コード例 #34
0
        public Album[] GetAlbums(Query query)
        {
            Album[] albums = null;
            if (query == null)
            {
                query = new Query
                {
                    PageIndex = 0,
                    PageSize = 1
                };
            }

            query.PageSize = query.PageSize == 0 ? 1 : query.PageSize;

            StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("SELECT i.InterpretID, i.Interpret, i.Interpret_Lang ,a.TitelID, a.Titel1, a.Guid as AlbumId FROM tunesEntities.titel AS a");
            stringBuilder.Append(" INNER JOIN tunesEntities.interpreten AS i ON a.InterpretID = i.InterpretID");
            stringBuilder.Append(" INNER JOIN tunesEntities.lieder AS t ON a.TitelID = t.TitelID");
            stringBuilder.Append(" WHERE t.Liedpfad IS NOT NULL");
			stringBuilder.Append(" GROUP BY i.InterpretID, i.Interpret, i.Interpret_Lang ,a.TitelID, a.Titel1, a.Guid");
            if (query.SortByCondition != null && query.SortByCondition.Id == 1)
            {
                stringBuilder.Append(" ORDER BY a.Titel1");
            }
            else
            {
                stringBuilder.Append(" ORDER BY i.Interpret, a.Titel1");
            }
            stringBuilder.Append(" SKIP @skip LIMIT @limit ");

            string sql = stringBuilder.ToString();

            using (System.Data.EntityClient.EntityConnection entityConnection =
                new System.Data.EntityClient.EntityConnection(this.ConnectionString))
            {
                try
                {
                    entityConnection.Open();
                    using (EntityCommand entityCommand = entityConnection.CreateCommand())
                    {
                        EntityParameter skip = new EntityParameter();
                        skip.ParameterName = "skip";
                        skip.Value = query.PageIndex;
                        entityCommand.Parameters.Add(skip);

                        EntityParameter limit = new EntityParameter();
                        limit.ParameterName = "limit";
                        limit.Value = query.PageSize;
                        entityCommand.Parameters.Add(limit);

                        List<Album> albumCollection = null;
                        entityCommand.CommandText = sql;
                        // Execute the command.
                        using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                        {
                            // Start reading results.
                            while (dataReader.Read())
                            {
                                if (albumCollection == null)
                                {
                                    albumCollection = new List<Album>();
                                }
                                Album album = new Album
                                {
                                    Artist = new Artist
                                    {
                                        Id = dataReader.GetInt32("InterpretID", false, 0),
                                        Name = dataReader.GetString("Interpret", false, string.Empty),
                                        SortName = dataReader.GetString("Interpret_Lang", true, string.Empty)
                                    },
                                    Id = dataReader.GetInt32("TitelID", false, 0),
                                    Title = dataReader.GetString("Titel1", false, string.Empty),
									AlbumId = dataReader.GetGuid("AlbumId", false, Guid.Empty)

                                };
                                albumCollection.Add(album);
                            }
                        }
                        if (albumCollection != null)
                        {
                            albums = albumCollection.ToArray();
                        }
                    }
                }
                finally
                {
                    entityConnection.Close();
                }
            }
            return albums;
        }
コード例 #35
0
 /// <summary>
 /// Add a EntityParameter with the given value to the collection at a location indicated by the index
 /// </summary>
 /// <param name="index">The index at which the parameter is to be inserted</param>
 /// <param name="value">The value of the parameter</param>
 public void Insert(int index, EntityParameter value)
 {
     this.Insert(index, (object)value);
 }
コード例 #36
0
        public Album GetAlbumById(int albumId)
        {
            Album album = null;

            StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("SELECT i.InterpretID, i.Interpret, i.Interpret_Lang ,a.TitelID, a.Titel1, a.Guid as AlbumId, a.ErschDatum, g.genreid, g.genre1");
            stringBuilder.Append(" FROM tunesEntities.titel AS a");
            stringBuilder.Append(" INNER JOIN tunesEntities.interpreten AS i ON a.InterpretID = i.InterpretID");
            stringBuilder.Append(" LEFT JOIN tunesEntities.genre AS g ON a.genreid = g.genreid");
            stringBuilder.Append(" WHERE a.titelid = @albumId");

            string sql = stringBuilder.ToString();

            using (System.Data.EntityClient.EntityConnection entityConnection =
                    new System.Data.EntityClient.EntityConnection(this.ConnectionString))
            {
                try
                {
                    entityConnection.Open();
                    using (EntityCommand entityCommand = entityConnection.CreateCommand())
                    {
                        EntityParameter id = new EntityParameter();
                        id.ParameterName = "albumid";
                        id.Value = albumId;
                        entityCommand.Parameters.Add(id);
                        entityCommand.CommandText = sql;
                        using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                        {
                            if (dataReader.Read())
                            {
                                album = new Album
                                {
                                    Artist = new Artist
                                    {
                                        Id = dataReader.GetInt32("InterpretID", false, 0),
                                        Name = dataReader.GetString("Interpret", false, string.Empty),
                                        SortName = dataReader.GetString("Interpret_Lang", true, string.Empty)
                                    },
                                    Id = dataReader.GetInt32("TitelID", false, 0),
                                    Title = dataReader.GetString("Titel1", false, string.Empty),
									AlbumId = dataReader.GetGuid("AlbumId", false, Guid.Empty),
									Year = dataReader.GetInt32("ErschDatum", true, 0),
                                    Genre = new Genre
                                    {
                                        Id = dataReader.GetInt32("genreid", true, 0),
                                        Name = dataReader.GetString("genre1", true, string.Empty)
                                    }
                                };
                            }
                        }
                        GetAlbumTracksByTitelId(album, entityConnection);
                    }
                }
                finally
                {
                    entityConnection.Close();
                }
            }
            return album;
        }
コード例 #37
0
        /// <summary>
        /// Clones this parameter object
        /// </summary>
        /// <returns>The new cloned object</returns>
        private void CloneHelper(EntityParameter destination)
        {
            CloneHelperCore(destination);

            destination._parameterName = _parameterName;
            destination._dbType = _dbType;
            destination._edmType = _edmType;
            destination._precision = _precision;
            destination._scale = _scale;
        }
コード例 #38
0
        public string GetAudioFileNameByGuid(Guid guid)
        {
            string fileName = null;
            string audioDirectory = this.AudioDirectory;
            if (string.IsNullOrEmpty(audioDirectory) == false && guid != null && guid != Guid.Empty)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT t.Liedpfad FROM tunesEntities.lieder AS t");
                stringBuilder.Append(" WHERE t.guid = @guid");

                string sql = stringBuilder.ToString();
                using (System.Data.EntityClient.EntityConnection entityConnection =
                        new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter guidParam = new EntityParameter();
                            guidParam.ParameterName = "guid";
                            guidParam.Value = guid.ToString();
                            entityCommand.Parameters.Add(guidParam);

                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                if (dataReader.Read() == true)
                                {
                                    fileName = GetTrackFilePath(dataReader, audioDirectory);
                                }
                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return fileName;
        }
コード例 #39
0
 /// <summary>
 /// Add a EntityParameter with the given name and value to the collection
 /// </summary>
 /// <param name="parameterName">The name of the parameter to add</param>
 /// <param name="value">The value of the parameter to add</param>
 /// <returns>The index of the new parameter within the collection</returns>
 public EntityParameter AddWithValue(string parameterName, object value)
 {
     EntityParameter param = new EntityParameter();
     param.ParameterName = parameterName;
     param.Value = value;
     return this.Add(param);
 }
コード例 #40
0
		public ICollection<Guid> GetPlaylistImageIdsById(int playlistId, string userName, int limit)
		{
			Collection<Guid> imageIds = null;
			if (string.IsNullOrEmpty(userName) == false)
			{
				StringBuilder stringBuilder = new StringBuilder();
				//stringBuilder.Append("SELECT a.Guid, COUNT(a.Guid) AS Number FROM tunesEntities.playlist AS p");
                stringBuilder.Append("SELECT a.Guid FROM tunesEntities.playlist AS p");
				stringBuilder.Append(" LEFT JOIN tunesEntities.playlistentries AS pe ON p.ListId = pe.PlaylistId");
				stringBuilder.Append(" LEFT JOIN tunesEntities.lieder AS t ON pe.LiedId = t.LiedID");
				stringBuilder.Append(" LEFT JOIN tunesEntities.titel AS a ON t.TitelID = a.TitelID");
				stringBuilder.Append(" WHERE p.ListId = @playlistId");
				stringBuilder.Append(" AND p.User = @userName");
                stringBuilder.Append(" ORDER BY pe.sortorder");
				stringBuilder.Append(" LIMIT @limit ");

				string sql = stringBuilder.ToString();
				using (System.Data.EntityClient.EntityConnection entityConnection =
				   new System.Data.EntityClient.EntityConnection(this.ConnectionString))
				{
					try
					{
						entityConnection.Open();
						using (EntityCommand entityCommand = entityConnection.CreateCommand())
						{
							EntityParameter idParam = new EntityParameter();
							idParam.ParameterName = "playlistId";
							idParam.Value = playlistId;
							entityCommand.Parameters.Add(idParam);

							EntityParameter user = new EntityParameter();
							user.ParameterName = "userName";
							user.Value = userName;
							entityCommand.Parameters.Add(user);

							EntityParameter limitParam = new EntityParameter();
							limitParam.ParameterName = "limit";
							limitParam.Value = limit;
							entityCommand.Parameters.Add(limitParam);

							entityCommand.CommandText = sql;
							// Execute the command.
							using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
							{
								while (dataReader.Read())
								{
									if (imageIds == null)
									{
										imageIds = new Collection<Guid>();
									}
                                    imageIds.Add(dataReader.GetGuid("Guid", true, Guid.Empty));
								}
							}
						}
					}
					finally
					{
						entityConnection.Close();
					}
				}
			}
			return imageIds;
		}
コード例 #41
0
 /// <summary>
 /// Adds a range of EntityParameter objects to this collection
 /// </summary>
 /// <param name="values">The arary of EntityParameter objects to add</param>
 public void AddRange(EntityParameter[] values)
 {
     this.AddRange((Array)values);
 }
コード例 #42
0
        public Playlist[] GetPlaylistsByUserName(string userName, int limit)
        {
            Playlist[] playlists = null;
            if (!string.IsNullOrEmpty(userName))
            {
                bool hasLimit = false;
                if (limit > 0)
                {
                    hasLimit = true;
                }

                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("SELECT p.ListId, p.ListName, p.User, p.guid FROM tunesEntities.playlist AS p");
                stringBuilder.Append(" WHERE p.User = @userName");
                stringBuilder.Append(" ORDER BY p.ListName");
                if (hasLimit)
                {
                    stringBuilder.Append(" LIMIT @limit ");
                }
                string sql = stringBuilder.ToString();

                using (System.Data.EntityClient.EntityConnection entityConnection =
                    new System.Data.EntityClient.EntityConnection(this.ConnectionString))
                {
                    try
                    {
                        entityConnection.Open();
                        using (EntityCommand entityCommand = entityConnection.CreateCommand())
                        {
                            EntityParameter user = new EntityParameter();
                            user.ParameterName = "userName";
                            user.Value = userName;
                            entityCommand.Parameters.Add(user);

                            EntityParameter limitParam = new EntityParameter();
                            limitParam.ParameterName = "limit";
                            limitParam.Value = limit;
                            entityCommand.Parameters.Add(limitParam);

                            List<Playlist> playlistCollection = null;
                            entityCommand.CommandText = sql;
                            // Execute the command.
                            using (EntityDataReader dataReader = entityCommand.ExecuteReader(System.Data.CommandBehavior.SequentialAccess))
                            {
                                // Start reading results.
                                while (dataReader.Read())
                                {
                                    if (playlistCollection == null)
                                    {
                                        playlistCollection = new List<Playlist>();
                                    }

                                    Playlist playlist = new Playlist
                                    {
                                        Id = dataReader.GetInt32("ListId", false, 0),
                                        Name = dataReader.GetString("ListName", false, string.Empty),
                                        UserName = dataReader.GetString("User", false, string.Empty),
                                        Guid = dataReader.GetGuid("guid", true, Guid.Empty)
                                    };
                                    playlistCollection.Add(playlist);
                                }
                            }
                            if (playlistCollection != null)
                            {
                                playlists = playlistCollection.ToArray();

                            }
                        }
                    }
                    finally
                    {
                        entityConnection.Close();
                    }
                }
            }
            return playlists;
        }
コード例 #43
0
 /// <summary>
 /// Copies the given array of parameters into this collection
 /// </summary>
 /// <param name="array">The array to copy into</param>
 /// <param name="index">The index in the array where the copy starts</param>
 public void CopyTo(EntityParameter[] array, int index)
 {
     this.CopyTo((Array)array, index);
 }
コード例 #44
0
 /// <summary>
 /// Finds the index in the collection of the given parameter object
 /// </summary>
 /// <param name="value">The parameter to search for</param>
 /// <returns>The index of the parameter, -1 if not found</returns>
 public int IndexOf(EntityParameter value)
 {
     return IndexOf((object)value);
 }
コード例 #45
0
 /// <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;
 }