SQL 存储过程
1.创建存储过程一列字符串合并成一个字符串
CREATE PROCEDURE GetTagInfo
@ObjectId int
AS BEGIN
DECLARE @STR nvarchar(MAX)
SELECT @STR=ISNULL(@STR+',','')+Name FROM [dbo].[TagInfoes] where Id in (select TagId from [dbo].[ObjectTags] where ObjectId=@ObjectId)
SELECT @STR as TagList
END GO
--查询
execute GetTagInfo '2'
调用:
#region 获取关键字字符串
SqlParameter[] parameters =
{
new SqlParameter{ ParameterName = "ObjectId",Value=sc.Id}
};
List<TagListModel> tagInfo = appDBContext.Database.SqlQuery<TagListModel>("EXEC GetTagInfo @ObjectId", parameters).ToList();
#endregion
类型:
public class TagListModel
{
public string TagList { get; set; }
}