Linq UNION query to select two elements

前端 未结 1 730
孤独总比滥情好
孤独总比滥情好 2020-12-31 00:47

I want to select 2 elements from my database table using LINQ query and I saw an example which use UNION I don\'t have much experience but I think

相关标签:
1条回答
  • 2020-12-31 01:03

    EDIT:

    Ok I found why the int.ToString() in LINQtoEF fails, please read this post: Problem with converting int to string in Linq to entities

    This works on my side :

            List<string> materialTypes = (from u in result.Users
                                          select u.LastName)
                           .Union(from u in result.Users
                                   select SqlFunctions.StringConvert((double) u.UserId)).ToList();
    

    On yours it should be like this:

        IList<String> materialTypes = ((from tom in context.MaterialTypes
                                           where tom.IsActive == true
                                           select tom.Name)
                                           .Union(from tom in context.MaterialTypes
                                           where tom.IsActive == true
                                           select SqlFunctions.StringConvert((double)tom.ID))).ToList();
    

    Thanks, i've learnt something today :)

    0 讨论(0)
提交回复
热议问题