How come setting OrganizationName = null does not work? I am doing a union and would like to set the value to null.
from a in Activities
select new
{
a.ActivityID,
a.ActivityName,
a.OrganizationID,
OrganizationName = null
}
...
OK OK, I know this is a hack, but this was for a tiny data-manipulation project and I wanted to play around. ;-)
I was always under the impression that the compiler would examine all anonymous types used in a C# program and if the properties were the same, it would only create one class behind the scenes.
So let's say I want to create ...
When I do a query that returns an anonymous type
var assets =
from Product p in Session.CreateLinq<Product>()
where bundles.Contains(p.ProductBundle)
select new {p.Asset, p.Asset.PropertyTbl};
Can I type the return to anything other than var?
...
Hi,
i have this linq to entities query:
c.CreateQuery<T_Hotels>("T_Hotels").Where(item => item.Id > 0).GroupBy(item => new { item.Location, item.Name }).Select(group => new { group.Key, Total = group.Sum(item => item.Id) })
I want to implement everything in a method of a class Helper, how declare the expressions of GroupBy and Select...
var emps = from x in DB
where x.ID = 100
select x;
var emp1 = from x1 in DB
where x1.ID = 100
select new { x };
What is difference between these two queries.
If we use anonymous-types is the performance will be increased or any other differences also there?
...
Is there any way to create anonymous type that references instances of itself?
var root = new { Name = "Root", Parent = ??? };
var child = new { Name = "Child", Parent = root };
var childOfChild = new { Name = "Grand child", Parent = child };
For example, we can reference delegate from itself:
Action run = null;
run = () => run();
...
I'm using anonymous types to pass collections of typed objects to a TemplateResolver, where the named placeholders in a newly instantiated text template may source values from multiple objects, e.g.
var body = TemplateResolver.ResolveTemplate(template.ExternalRecipientBody, new {Sender = customer, NewJobCard = jobCard});
where the te...
I'm returning a Json'ed annonymous type:
IList<MyClass> listOfStuff = GetListOfStuff();
return Json(
new {
stuff = listOfStuff
}
);
In certain cases, I know that listOfStuff will be empty. So I don't want the overhead of calling GetListOfStuff() (which makes a database call).
So in this case I'm writing:
return Json(
...
Hi people, I have the a class Foo like this:
class Foo
{
public int id{get;set;}
public IEnumerable<Foo> Childs;
//some other properties
}
Now I want to process some business logic on a Foo-Object and all it's children like this:
public void DoSomeWorkWith(Foo x)
{
var firstItem = new {level = 0, item = x};
var s ...
In my plugin architecture I am currently passing a plugin name (string), method name (string) and parameters (object array) to my plugin service to execute the specified method and return the result (of type T).
The plugin service's execute method can be seen below:
public TResult Execute<TResult>(string pluginName, string operation, p...
Hi,
I'm trying to avoid a dynamic type in my lambda expression for grouping a collection. The type is defined anonymously at compile time (and unambiguously as far as I can tell). I'd rather not define the type as a full-fledged class as I'm only using it a few times in this single method.
Sample code:
Func<MyData, dynamic> dataGroupi...
I'm new to anonymous classes, and today I think I ran into the first case where I felt like I could really use them. I'm writing a method that would benefit from storing temporary data inside of a class, and since that class doesn't have any meaning outside of that method, using an anonymous class sure made sense to me (at least at the ...
Consider the requirement to always declare Option Strict On. We'll always need to declare variables with the As keyword. What would be the type of an anonymous type?
Example : Dim product As ... = New With { Key .Name = "paperclips", .Price = 1.29 }
What will follow the As?
...
I have a piece of code that filters a list using LINQ, creates a list of instances of an anonymous type, and assigns an event handler to each instance:
// Select every linear expression and create a menu item from it
var items = from expr in expressionList.Expressions
where expr.Type == ExpressionType.Linear
let ...
I have two nested repeaters in my *.aspx page.
<asp:Repeater runat="server" id="rptMain">
<ItemTemplate>
<h1><%#DataBinder.Eval(Container.DataItem, "Name")%></h1>
<asp:Repeater runat="server" DataSource='<%# getUser(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "FieldKey"))) %>'>
<HeaderTemplate><ol>...
I wish to construct a list of anonymous types constructed by iterating through two other lists in a nested loop.
var myList = new List<???>();
foreach (object x in GetAllX())
{
if (Process(x))
{
foreach (object y in GetAllY(x))
{
myList.Add(new {
X = x,
Y = y
...
I have the following anonymous type:
new {data1 = "test1", data2 = "sam", data3 = "bob"}
I need a method that will take this in, and output key value pairs in an array or dictionary.
My goal is to use this as post data in an HttpRequest so i will eventually concatenate in into the following string:
"data1=test1&data2=sam&data3=bob"...
Is there any way to serialize an anonymous type in .net? Normal XmlSerializer fails because the type has no parameterless constructor defined; and NetDataContractSeralizer fails becuase we can't tag DataContract or Serializable attribute to anonymous class.
So is there any clever way around or we just can't do it?
...
How could it be possible to union the members of instances of two or more anonymous (or maybe not anonymous) types, to create a resulting type instance with all the members?
Pseudocode example:
var anon1 = new {FirstName = "Bill"};
var anon2 = new {Surname = "Hicks"};
var anon3 = anon1.Union(anon2);
Debug.WriteLine(anon3.FirstName + "...
I've pieced together some information from other posts but I'm stuck.
The first part works fine. Basically I query the database using LINQ and then I loop through the results generating a report.
Dim results As System.Linq.IQueryable(Of Bud900Reports.tblBud_CONNECT)
If options.Type = reportType.Organization Then
results = From...