有没有办法可以查看我的Linq-to-entities查询使用EF框架生成的Entity Sql(eSQL)(即,不是本机SQL,而是eSQL,如果有意义的话?)
谢谢!
我的自定义比较器似乎不起作用.我想要一些不同的对象,但我每次都得到1.即使查看数据库本身清楚地显示查询还有1个具有不同"TimeOfAction"值的实例.
class TimeComparer : IEqualityComparer<Action>
{
public bool Equals(Action a, Action b)
{
if (a.TimeOfAction == b.TimeOfAction)
return true;
else
return false;
}
public int GetHashCode(Action obj)
{
return obj.ToString().ToLower().GetHashCode();
}
}
Run Code Online (Sandbox Code Playgroud)
认为它可能是GetHashCode方法,因为我不太熟悉它的工作方式.这是linq查询.我转换为AsEnumerable,因为Linq to Entities不支持distinct方法.
DBEntities db = new DBEntities();
IEnumerable<Action> query =
from action in db.Action.AsEnumerable()
where action.TimeOfAction > new DateTime(2010, 11, 1, 0, 0, 0)
where action.TimeOfAction < new DateTime(2011, 2, 7, 0, 0, 0)
where action.EntityName == "seant"
select action;
var count = query.
Distinct(new TimeComparer()).Count();
Run Code Online (Sandbox Code Playgroud) 我试图在c ++中重载[]运算符,以便我可以从我的数据结构中分配/获取值,就像在c#中使用字典一样:
数组["myString"] =等
这在c ++中是否可行?
我试图超载操作员,但它似乎没有工作,
Record& MyDictionary::operator[] (string& _Key)
{
for (int i = 0; i < used; ++i)
{
if (Records[i].Key == _Key)
{
return Records[i];
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.