高友峰 發表於 2025-3-26 06:12:00

Ai满嘴顺口溜,想考研?浪费我几个小时

<p>Trae + claude3.7</p>
<p>事情的经过是这样的:</p>
<p>我有个方法代码如下:</p>
<div class="cnblogs_code">
<pre>       <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
      <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 获取客户端列表
      </span><span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
      <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="input"&gt;</span><span style="color: rgba(0, 128, 0, 1)">查询条件参数,包含搜索、排序和分页信息</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
      <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;param name="cancellationToken"&gt;</span><span style="color: rgba(0, 128, 0, 1)">异步取消标记</span><span style="color: rgba(128, 128, 128, 1)">&lt;/param&gt;</span>
      <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;returns&gt;</span><span style="color: rgba(0, 128, 0, 1)">客户端数据集合</span><span style="color: rgba(128, 128, 128, 1)">&lt;/returns&gt;</span>
      <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">async</span> Task&lt;Khdsc&gt; GetClientsAsync(Hqkhdsr input, CancellationToken cancellationToken = <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)">)
      {
            </span><span style="color: rgba(0, 0, 255, 1)">var</span> q =<span style="color: rgba(0, 0, 0, 1)"> db.Clients.AsNoTracking();

            </span><span style="color: rgba(0, 0, 0, 1)"><span style="color: rgba(0, 0, 255, 1)">//条件和排序...略...</span></span><span style="color: rgba(0, 0, 0, 1)">

            logger.LogWarning(</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">执行GetClientsAsync</span><span style="color: rgba(128, 0, 0, 1)">"</span> +<span style="color: rgba(0, 0, 0, 1)"> tp.GetUtcNow());
            </span><span style="color: rgba(255, 0, 0, 1)"><strong>var total = await q.CountAsync(cancellationToken);
            </strong></span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">await Task.Delay(3000);</span>
            q = q.OrderBy(input.sort + <span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(128, 0, 0, 1)">"</span> + input.Order).Skip(input.Offset).Take(input.Limit);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> .Page(input.Limit, input.Offset / input.Limit + 1);</span>
            <strong><span style="color: rgba(255, 0, 0, 1)">var list = await q.ToListAsync(cancellationToken);

            </span></strong><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Khdsc
            {
                BridgePort </span>= <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)">,
                BridgeType </span>= <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)">,
                Ip </span>= <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)">,
                Total </span>=<span style="color: rgba(0, 0, 0, 1)"> total,
                Rows </span>=<span style="color: rgba(0, 0, 0, 1)"> list.Select(MapClientEntityToKhdrow).ToList(),
            };
      }</span></pre>
</div>
<p>然后执行报错了:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">在 Microsoft.EntityFrameworkCore.Infrastructure.Internal.ConcurrencyDetector.EnterCriticalSection()
在 Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`</span><span style="color: rgba(128, 0, 128, 1)">1</span>.AsyncEnumerator.&lt;MoveNextAsync&gt;<span style="color: rgba(0, 0, 0, 1)">d__20.MoveNext()
在 System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`</span><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.ConfiguredValueTaskAwaiter.GetResult()
在 Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.</span>&lt;ToListAsync&gt;d__67`<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.MoveNext()
在 Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.</span>&lt;ToListAsync&gt;d__67`<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.MoveNext()
在 YCSDK.Sdf.</span>&lt;GetClientsAsync&gt;d__12.MoveNext() 在 D:\fyjiot\src\YCSKDFolder\YCSDK\Sdf.cs 中: 第 <span style="color: rgba(128, 0, 128, 1)">171</span><span style="color: rgba(0, 0, 0, 1)"> 行
在 YCSDK.RCL.Client.ClientList.</span>&lt;LoadClientListAsync&gt;d__17.MoveNext() 在 D:\fyjiot\src\YCSKDFolder\YCSDK.RCL\Client\ClientList.razor.cs 中: 第 <span style="color: rgba(128, 0, 128, 1)">77</span> 行</pre>
</div>
<p>有经验的老表一看就晓得是多线程使用同一个dbcontext实例出的问题。所以我仔细排查了我的代码,实在看不出问题,想想问问Ai吧,对话如下:</p>
<p><img src="https://img2024.cnblogs.com/blog/350763/202503/350763-20250326055104740-1678372720.png" alt="" loading="lazy"></p>
<p><img src="https://img2024.cnblogs.com/blog/350763/202503/350763-20250326055133442-1332656310.png" alt="" loading="lazy"></p>
<p><img src="https://img2024.cnblogs.com/blog/350763/202503/350763-20250326055203238-30194551.png" alt="" loading="lazy"></p>
<p>看到这里我开始怀疑我自己了,也想不通微软为什么要在efcore9中做出这样的改变,会不会是ef9有bug?这样设计不合理啊。</p>
<p>然后我就开始换豆包、chatgpt、千问,各种问,它们基本没法提供有价值的信息。然后又直接各种搜索,由于ef9太新,也搜不出啥东东来。</p>
<p>然后又建测试项目,单独测试又没问题,这个时候我就开始怀疑开始Ai给的回答了,</p>
<p>最终各种折腾发现问题是我用的antblazor刷新数据默认是开了线程的,<span style="color: rgba(255, 0, 0, 1)"><strong>重点是界面部分我也是让Ai它帮我写的。</strong></span></p>
<p>到这里问题就解决了。</p>
<p>&nbsp;</p>
<p>我想说的是,我开始问ai它给了我一个错误的回答,辛亏我了解这里,所以质疑它,但它居然再次回答时说得有理有据,我不信邪再次问他是不是ef9的版本导致的,它也说得头头是道。</p>
<p>如果不熟悉ef的人估计会被它带偏,对ef9会产生一种错误的认识,搞得不好还会去把老项目都重构下,浪费时间,以后发现不是ef9的问题又重构回去,再浪费一次时间。</p>
<p>&nbsp;</p>
<p>所以感觉目前的Ai有个陷阱,就是让不了解某个领域的人,可以用Ai去完成那个领域的事,同时埋一堆雷在那里。</p><br><br>
来源:https://www.cnblogs.com/jionsoft/p/18792692
頁: [1]
查看完整版本: Ai满嘴顺口溜,想考研?浪费我几个小时