本文介绍了使用LINQ to SQL时,这是一个虚假的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每我见过LINQ的例子很多,我用类似下面的一个代码创造我自己的数据上下文和表:

Per the many examples of LINQ I've seen, I'm creating my own data context and tables using code similar to the one below:

class MyDatabase : DataContext {
  public Table<Widget> Widgets;
  public Table<Car> Cars;

  public MyDatabase (string connection) : base(connection) { }
}

但是,每表(窗口小部件,汽车等),我得到的警告字段'表名'是从来没有分配即可。我找不到在谷歌的人也有这个问题。我不觉得我做的任何事情,因为我只是复制LINQ的例子我从不同的地方看到错误的。那么什么是与此警告?难道是警告我一个真正的问题呢?还是我失去了一些东西?

But for every table (Widgets, Cars, etc), I get the warning Field 'TableName' is never assigned. I can't find anyone on Google that also has this problem. I don't feel like I'm doing anything wrong since I'm just copying the LINQ examples I've seen from different places. So what's up with this warning? Is it warning me of a real problem? Or am I missing something?

推荐答案

是的,他们是虚假的。*

Yes, they are spurious.*

在,我们了解到了的DataContext 使用反射来填充在运行时的字段。因此,Visual Studio是给你基于它在编译时知识的警告。它不知道他们正在消费之前最终这些字段将被填充。

In this other question about how DataContext works, we learn that the constructor for DataContext uses reflection to populate the fields at runtime. So Visual Studio is giving you a warning based on the knowledge it has at compile time. It does not know that ultimately these fields are populated before they are consumed.

*回答基于关别人的评论,所以发现。甚至可能是错误的!

*Answer based off of someone else's comment found on SO. Might even be wrong!

这篇关于使用LINQ to SQL时,这是一个虚假的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:25