Entity framework 我可以修改它以更好的方式修复此错误吗
这是我的密码Entity framework 我可以修改它以更好的方式修复此错误吗,entity-framework,Entity Framework,这是我的密码 using (var conn = new DataEntities()) { var query = from c in conn.servers where c.Servername != null select c; servers srv = query.FirstOrDefault(); if (srv != null)
using (var conn = new DataEntities())
{
var query = from c in conn.servers where c.Servername != null select c;
servers srv = query.FirstOrDefault();
if (srv != null)
{
Start.IPAddress = srv.ServerIP;
Start.ServerName = srv.Servername;
Start.GamePort = Convert.ToUInt16(srv.ServerPort);
}
Start.Servers.Add(Start.ServerName, Start.GamePort);
}
服务器srv=query.FirstOrDefault();//这里出错
未经处理的异常
type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.dll
Additional information: An error occurred while executing the command definition. See the inner exception for details.
能以通常更好的方式写信吗
一些建议我还是初学者^^
谢谢解决了
using (var conn = new DataEntities())
{
var query = from c in conn.servers
select new
{
c.Servername,
c.ServerPort,
c.ServerIP
};
foreach (var item in query)
{
Start.IPAddress = item.ServerIP;
Start.ServerName = item.Servername;
Start.GamePort = Convert.ToUInt16(item.ServerPort);
}
Start.Servers.Add(Start.ServerName, Start.GamePort);
}
什么是内部异常(
请参阅内部异常以了解详细信息。
)?这里是{“每个派生表都必须有自己的别名”}看起来您正在将EF与MySQL一起使用,MySQL正在引发该异常。感谢您的回复,这是我的查询错误,我解决了它谢谢