SELECT 0 AS GroupId, 'Select All' AS GroupName
UNION
SELECT GroupId, GroupName
FROM tbl_AccountGroup
Asked
Active
Viewed 82 times
0

Brian Mains
- 50,520
- 35
- 148
- 257

Mohammed Shafeeq
- 61
- 1
- 1
- 3
2 Answers
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
- 105,341
- 31
- 202
- 291

TheRealTy
- 2,409
- 3
- 22
- 32
-
Thanks for answering, But It resulting error as - "Cannot assign void to an implicitly-typed local variable" – Mohammed Shafeeq Feb 28 '12 at 09:56
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
-
Sorry, it resulting the Error :- The type arguments for method 'System.Linq.Enumerable.Union
(System.Collections.Generic.IEnumerable – Mohammed Shafeeq Feb 28 '12 at 09:56, System.Collections.Generic.IEnumerable )' cannot be inferred from the usage. Try specifying the type arguments explicitly. -
What type is GroupID and GroupName? I mean is GroupID a string(varchar) or an int? – Arion Feb 28 '12 at 10:07
-