我正在尝试为 WCF 服务执行 SQL 查询,因为我使用的数据库没有存储过程来返回我需要的数据。你可以看到下面的代码。我正在使用 VS2010 并连接到 Microsoft SQL Server。我得到的异常是:无法绑定多部分标识符。谢谢您的帮助。
public List<ObjectCodeGroup> GetObjectCodeGroup()
{
TCDataDataContext dc16 = new TCDataDataContext();
List<ObjectCodeGroup> results = new List<ObjectCodeGroup>();
var objectCodeResults = dc16.ExecuteQuery<ObjectCodeGroup>(@"select t1.codeid," +
"t1.code, t1.catalogtype, t1.codegroup, t1.codetext, t1.codegrouptext, t1.codedesc, t1.state_id from CODES t1" +
"inner join ( select MIN(codeid) codeid, codegroup from CODES group by codegroup)" +
"t2 on t1.codeid = t2.codeid and t1.codegroup = t2.codegroup WHERE catalogtype = 11");
foreach (ObjectCodeGroup o in objectCodeResults)
{
results.Add(new ObjectCodeGroup()
{
codegrouptext = o.codegrouptext
});
}
return results;
}