积极答复者
实体框架如何判断一个表是否有记录?

问题
-
想判断Entities1里的table1是否有记录
if (Entities1.table1!=null && Entities1.table1.Count()>0) //判断一个Entities里的实体是否有记录 =>一直报错
{......}
else
{......}
这段代码当table1里没有记录时就会报错为什么? 要如何判断实体是否有记录应该如何做?- 已移动 Leo Liu - MSFT 2011年9月2日 7:22 Moved for better support. (发件人:Visual C#)
答案
-
web.config或者是app.config 要如何配置才正确?
我的一直有这种错误: 当table1里没有记录时就会报错,有记录这段代码就不报错,奇怪的很
if (Entities1.table1!=null && Entities1.table1.Count()>0) =>对象名 'Entities1.table1' 无效
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处- 已标记为答案 tonny2003 2011年9月2日 7:24
全部回复
-
-
当table1里没有记录时就会报错
if (Entities1.table1!=null && Entities1.table1.Count()>0)
能否提供"详细"的错误讯息?
Shadowと愉快なコード達 -
-
当table1里没有记录时就会报错
if (Entities1.table1!=null && Entities1.table1.Count()>0) //判断是否有记录
当table1里有记录就不报错, 说明1.数据表里有table1这个表;2.在edmx里table1的EntitySetName是为table1
我完全可以的,我做了一个简单的表:其中id自增长,name是varchar(50)。表中无任何记录。
我建议你自己看看是否正确配置了web.config或者是app.config:
我的测试代码:
public class MyClass
{
public static void Main()
{
using (CSharp.Entities e = new CSharp.Entities())
{
Console.WriteLine(e.tbtest.Count());
}
}
}
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处 -
web.config或者是app.config 要如何配置才正确?
我的一直有这种错误: 当table1里没有记录时就会报错,有记录这段代码就不报错,奇怪的很
if (Entities1.table1!=null && Entities1.table1.Count()>0) =>对象名 'Entities1.table1' 无效
如果你有其它意见或私下交流,请直接发送maledong_work@foxmail.com;或者
If you do not have QQ, please open the page and download it and click the image to talk or leave message for me.
下载MSDN桌面工具(Vista,Win7)
下载Technet桌面小工具(Vista,Win7)
慈善点击,点击此处- 已标记为答案 tonny2003 2011年9月2日 7:24