Reputation: 153
I would like to do a full text search in my win forms application.
public static IEnumerable<DataRow> GetPartDataForFullTextSearch(string text1)
{
using (cEntity context = new cEntity())
{
var query = (
from i in context.tblparts
join s in context.tblpartstatus on i.partstatus
equals s.id
join l in context.tblwarehouse on i.partId
equals l.partId
join p in context.tblwarehouseplace on l.warehouseId
equals p.WhId
orderby i.partID
select new Part
{
PartNumber = i.partID,
PartName = i.partName,
OldPartNo = i.partIdOld,
Comment = i.comment,
Hbv = (long)i.HBVNr,
Status = (int)i.partstatus,
Building = p.building,
Room = p.room,
Shelf = p.shelf,
CaseOfPart = p.case
}).Distinct() as IEnumerable<DataRow>;
var results =
from matchingItem in query
where Regex.IsMatch(matchingItem.Field<string>("partName"), text1)
select matchingItem;
var list = results.ToList();
return list;
}
}
But I don't receive a result => ArgumentNullException
That's how I want to receive the results
private void tbOverviewFullSearch_TextChanged(object sender, EventArgs e)
{
dgPartOverview.DataSource =
DatabaseQueries.D_PartManagement
.GetPartDataForFullTextSearch(tbOverviewFullSearch.Text);
}
What's wrong? And is it possible to filter more than one field?
Upvotes: 1
Views: 1506
Reputation: 109252
You cannot cast an IQueryable<Part>
to IEnumerable<DataRow>
. Remove the cast and do
Regex.IsMatch(matchingItem.partName), text1)
Upvotes: 3