The text data type cannot be selected as DISTINCT because it is not comparable

I have a problem because there is an old third-party database with which I am trying to connect and retrieve data from it using the now obsolete text box. However, I cannot change the database fields, so this causes problems when trying to return data via LINQ. Sample code below:

var query = from s in db.tSearches
            join c in db.tCompanies on s.CompanyGUID equals c.GUID
            join cl in db.tCompanyLocations on s.LocationGUID equals cl.GUID
            join st in db.tSearchTypes on s.SearchTypeGUID equals st.GUID
            where s.DateClosed == null                        
            select new
            {
                Id = s.GUID,
                Type = st.GUID,
                Location = cl.LocationName,
                Company = (s.Confidential) ? String.Empty : c.CompanyName,
                DateOpened = s.DateOpened,
                Notes = s.PlacementNotes,
                Closed = s.DateClosed != null
            };

This information performs additional filtering before I eventually try to do this:

        return query.Select(x => new VacancySummary
        {
            Id = x.Id,
            Departments = "",
            Location = x.Location,
            Company = x.Company,
            DateOpened = x.DateOpened,
            Notes = x.Notes,
            Closed = x.Closed
        }).Distinct().Skip(skip).Take(take);

. SQL, , Distinct, , , .

?

+3
2

text?

, Distinct() , SQL. , LINQ to Objects Distinct().

, , :

var query = (from s in db.tSearches
            join c in db.tCompanies on s.CompanyGUID equals c.GUID
            join cl in db.tCompanyLocations on s.LocationGUID equals cl.GUID
            join st in db.tSearchTypes on s.SearchTypeGUID equals st.GUID
            where s.DateClosed == null                        
            select new VacancySummary()
            {
                Id = s.GUID,
                Departments = string.Empty,
                Type = st.GUID,
                Location = cl.LocationName,
                Company = (s.Confidential) ? String.Empty : c.CompanyName,
                DateOpened = s.DateOpened,
                Notes = s.PlacementNotes,
                Closed = s.DateClosed != null
            }).ToList();

query List<VacancySummary> IQueryable<anonymous type>. , Equals() VacancySummary, , :

return query.Distinct().Skip(skip).Take(take);

: , , .

2: - , Entity Framework? . (, , , text varchar(max) (.. CONVERT(varchar(max), PlacementNotes))). LINQ, SQL. , , , , !

+2

linq, tsql varchar, . ToString() Expression.Convert , , , , 8000 .

+1

All Articles