1

我想在我的 win forms 应用程序中进行全文搜索。

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;
    }
}

但我没有收到结果 => ArgumentNullException

这就是我希望收到结果的方式

      private void tbOverviewFullSearch_TextChanged(object sender, EventArgs e)
{
    dgPartOverview.DataSource = 
        DatabaseQueries.D_PartManagement
            .GetPartDataForFullTextSearch(tbOverviewFullSearch.Text);
}

怎么了?是否可以过滤多个字段?

4

1 回答 1

2

您不能投射IQueryable<Part>to IEnumerable<DataRow>。移除演员表并做

Regex.IsMatch(matchingItem.partName), text1)
于 2012-10-25T10:12:02.173 回答