【发布时间】:2017-04-04 15:03:53
【问题描述】:
我想知道是否可以以某种方式查询我用作主键的类的某个属性。 我的想法类似于下面的代码。使用 _key.NAME 我收到错误消息说列不存在,我也尝试使用 TestOjectPK.NAME,但没有成功:
var fieldsQuery = new SqlFieldsQuery("select _val,_key from TestObject where _key.NAME= ? and VALUE= ?", "name1","value");
IQueryCursor<IList> queryCursor = cache.QueryFields(fieldsQuery);
这是我用 3 列表示某个表的类,其中 2 列是 PK。
class TestObjectPK : IBinarizable
{
private Int32 id;
private String name;
[QuerySqlField]
public string NAME
{
get{return this.name;}
set{this.name = value;}
}
[QuerySqlField]
public Int32 ID
{
get{return this.id;}
set{this.id = value;}
}
public void WriteBinary(IBinaryWriter writer)
{
writer.WriteInt("ID", ID);
writer.WriteString("NAME", NAME);
}
public void ReadBinary(IBinaryReader reader)
{
ID = reader.ReadInt("ID");
NAME = reader.ReadString("NAME");
}
public override int GetHashCode()
{
return id.GetHashCode() + name.GetHashCode();
}
public override bool Equals(object obj)
{
return id == ((TestObjectPK)obj).id && name == ((TestObjectPK)obj).NAME;
}
}
class TestObject : IBinarizable
{
private String value2;
[QuerySqlField]
public String VALUE
{
get { return this.value2; }
set { this.value2 = value; }
}
public void WriteBinary(IBinaryWriter writer)
{
writer.WriteString("VALUE", VALUE);
}
public void ReadBinary(IBinaryReader reader)
{
VALUE = reader.ReadString("VALUE");
}
public override int GetHashCode()
{
return VALUE.GetHashCode();
}
public override bool Equals(object obj)
{
return VALUE == ((TestObject)obj).VALUE;
}
}
【问题讨论】: