the data like this: file1 file2 aaaa milk aaaa red bbbb box bbbb pen cccc rose i want get result like this: file1: aaaa bbbb cccc who can tell me how to do using DB4objects waiting online....
+1
A:
As far as I know db4o has no direct support for the 'distinct' operation. However since you're using the .NET-framework you can use the LINQ-Distinct operation on you result. I assume you're using .NET 3.5 and C#. Tell me when I'm wrong.
For example:
IObjectContainer db = // ...
var persons = (from Person p in db
select p).Distinct();
This will return the distinct result of all Person-objects. It will use the GetHashCode() and Equals()-Methods to compare the objects.
When you don't want to use a the default equal comparison, you can pass an IEqualityOperator-instance to the distinct method:
class PersonByNameEquality : IEqualityComparer<Person>
{
public bool Equals(Person x, Person y)
{
return x.Firstname.Equals(y.Firstname);
}
public int GetHashCode(Person obj)
{
return obj.Firstname.GetHashCode();
}
}
// and then
IObjectContainer db = //...
var persons = (from Person p in db
select p).Distinct(new PersonByNameEquality());
Gamlor
2010-03-30 11:48:41