0
SELECT        0 AS GroupId, 'Select All' AS GroupName
UNION
SELECT        GroupId, GroupName
FROM            tbl_AccountGroup
Brian Mains
  • 50,194
  • 35
  • 142
  • 253

2 Answers2

0
var lst = context.tbl_AccountGroup.Select(a => new {a.GroupID, a.GroupName})
    .ToList();
lst.Insert(0, new {GroupID = 0, GroupName = "Select All"});

Something similar to that may work.. untested. Depending on how your using it there may be better ways.

Gert Arnold
  • 100,019
  • 29
  • 193
  • 278
TheRealTy
  • 2,399
  • 3
  • 20
  • 32
0

This will do a UNION ALL. So that all the values are comming:

var result= Enumerable.Range(0,1)
            .Select (s => new {GroupID= 0,GroupName="Select all" })
            .Concat
            (
                db.tbl_AccountGroup
                .Select(a => new {GroupID=a.GroupID, GroupName=a.GroupName})
               .AsEnumerable()
            );

Or i don't know if you really want a UNION. If you want a UNION that means that the values are distinct between the statements. Then you have to do like this:

var result= Enumerable.Range(0,1)
            .Select (s => new {GroupID= 0,GroupName="Select all" })
            .Union
            (
                db.tbl_AccountGroup
                .Select(a => new {GroupID=a.GroupID,GroupName=a.GroupName})
               .AsEnumerable()
            );

See the diffrence between a UNION and UNION ALL here

Community
  • 1
  • 1
Arion
  • 30,443
  • 10
  • 68
  • 86
  • Sorry, it resulting the Error :- The type arguments for method 'System.Linq.Enumerable.Union(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly. – Mohammed Shafeeq Feb 28 '12 at 09:56
  • What type is GroupID and GroupName? I mean is GroupID a string(varchar) or an int? – Arion Feb 28 '12 at 10:07
  • GroupID- int, GroupName- nvarchar(MAX) – Mohammed Shafeeq Feb 28 '12 at 10:29