title: How to use IN Clause for list of strings or GUID's in Dapper
body: <p>I am trying to write a dapper query for IN clause, but it's not working throwing casting error saying "Conversion failed when converting the nvarchar value 'A8B08B50-2930-42DC-9DAA-776AC7810A0A' to data type int." . In below query fleetAsset is Guid converted into string.</p>
  
  <pre><code>public IQueryable&lt;MarketTransaction&gt; GetMarketTransactions(int fleetId, int userId, int rowCount)
  {
      //Original EF queries which I am trying to convert to Dapper
  
      //var fleetAsset = (from logicalFleetNode in _context.LogicalFleetNodes
      //                  where logicalFleetNode.LogicalFleetId == fleetId
      //                  select logicalFleetNode.AssetID).ToList();
  
      ////This query fetches guid of assetprofiles for which user having permissions based on the assets user looking onto fleet
      //var assetProfileIds = (from ap in _context.AssetProfileJoinAccounts
      //                       where fleetAsset.Contains(ap.AssetProfile.AssetID) &amp;&amp; ap.AccountId == userId
      //                       select ap.AssetProfileId).ToList();
  
      var fleetAsset = _context.Database.Connection.Query&lt;string&gt;("SELECT CONVERT(varchar(36),AssetID) from LogicalFleetNodes Where LogicalFleetId=@Fleetid",
          new { fleetId }).AsEnumerable();
  
      //This query fetches guid of assetprofiles for which user having permissions based on the assets user looking onto fleet
      var sql = String.Format("SELECT TOP(@RowCount) AssetProfileId FROM [AssetProfileJoinAccounts] AS APJA WHERE ( EXISTS (SELECT " +
                              "1 AS [C1] FROM  [dbo].[LogicalFleetNodes] AS LFN " +
                              "INNER JOIN [dbo].[AssetProfile] AS AP ON [LFN].[AssetID] = [AP].[AssetID]" +
                                  " WHERE ([APJA].[AssetProfileId] = [AP].[ID])  " +
                                  " AND ([APJA].[AccountId] = @AccountId AND LogicalFleetId IN @FleetId)))");
      var assetProfileIds = _context.Database.Connection.Query&lt;Guid&gt;(sql, new { AccountId = userId, FleetId = fleetAsset, RowCount=rowCount });
  </code></pre>