See the code below, I don't know why my ordering is not working, any ideas?
var orderSample = new { ProductName = "", Qty = 0, UserFullName = "" };
var ordersList = (new[] { orderSample }).ToList();
//loop thru another collection and fill ordersList by adding an order at a time
ordersList.Add(new { ProductName = "Product1", Qty = 5, Us...
Hello,
I have a linq query which returns the ID of a question based on the questions text.
This ID is then needed to be used to relate a date in a date table to that particular question. The question is already stored and the date is stored at a different time.
The problem is that the query returns the questionID as an anonymous type a...
OK,
This is something that I cannot believe I have not been able to figure out -- please tell me I am missing someting simple...
I have a datagrid, I am filling it with Linq as well as a custom class to add data to it.
Afterwards, I need the data in a specific order - it seems to ignore me.
How do I change a columns properties, like ...
i want to create an anonymous class in vb.net exactly like this:
var data = new {
total = totalPages,
page = page,
records = totalRecords,
rows = new[]{
new {id = 1, cell = new[] {"1", "-7", "Is this a good question?"}},
new {id = 2,...
from the free dinner book for asp.net MVC
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection formValues) {
Dinner dinner = dinnerRepository.GetDinner(id);
UpdateModel(dinner);
dinnerRepository.Save();
return RedirectToAction("Details", new { id = dinner.DinnerID });
}
how to convert this line...
I develop a reporting engine where reports are based on templates. Every template has string with SQL query and every report has specific values for SQL query parameters. To render a report I set parameters and call DataContext.ExecuteQuery method to get list of records. But to catch returned columns I have to know their names and have a...
In C#, is there a way (terser the better) to resolve the name of a parameter at runtime?
For example, in the following method, if you renamed the method parameter, you'd also have to remember to update the string literal passed to ArgumentNullException.
public void Woof(object resource)
{
if (resource == null)
{...
I have a datagrid populated by a Linq query. When the focused row in the datagrid changes I need to set a variable equal to one of the properties in that object.
I tried...
var selectedObject = view.GetRow(rowHandle);
_selectedId = selectedObject.Id;
... but the compiler doesn't care for this at all ("Embedded statement cannot be a d...
Hello,
My first try to use anonymous types(test):
private void button4_Click(object sender, EventArgs e)
{
test(new { a = "asd" });
}
private void test(string a)
{
}
I get an error "cannot convert from 'AnonymousType#1' to 'string' "
Also I'd like to know how to pass an anonymous type if the paramete...
Possible Duplicates:
C# 'var' keyword versus explicitly defined variables
C# - Do you use "var"?
This is a relatively simple question...more of a poll really. I am a HUGE fan of C#, and have used it for over 8 years, since before .NET was first released. I am a fan of all of the improvements made to the language, including lam...
What I really want is to select these two tables in to an anon type like in Scott Gu's blog: here However, I would settle for this created type "ActiveLots" I am joining two tables together and want to be able to reference columns from each in my result set.
I don't seem to be getting the syntax correctly.
Dim pi = From p In dc.Inve...
I have read in some blog some time ago (sorry for being vague) that i could use a linq like the following
var list = from c in xml
select new
{
foreach(XElement el in c.Elements())
{
}
}
Does anyone know is it possible or is it just my imagination??
Thanks.
...
in c#,
var x = new {};
declares an anonymous type with no properties. Is this any different from
var x = new object();
?
...
What are the best use cases for anonymous types?
It would seem to me that they are only useful within a limited context, for example one class or one function. They can hardly be used outside of this context, because without reflection no one will know what properties are available on these types.
...
How can I get output from Java anonymous classes? In .Net I would use closures.
executor = Executors.newSingleThreadExecutor();
final Runnable runnable = new Runnable() {
public Exception exception;
@Override
public void run() {
try {
doSomething();
}
catch (Exception exception) {
// I'd like to report thi...
Possible Duplicate:
LINQ to SQL: Return anonymous type?
I have a standard LINQ to SQL query, which returns the data as an anonymous type (containing about 6 columns of data of various datatypes).
I would like to make this returned object available to other parts of the program, either by returning it to the method-caller, or by...
I'm a Linq noobie, maybe someone can point me in the right direction. What's wrong here? These anonymous types seem to have the same signatures.
'*** Get all of the new list items'
Dim dsNewFiles = From l1 In list1 _
Where Not (From l2 In list2 _
Select...
I have this:
List<object> nodes = new List<object>();
nodes.Add(
new {
Checked = false,
depth = 1,
id = "div_" + d.Id
});
... and I'm wondering if I can then grab the "Checked" property of the anonymous object. I'm not sure if this is even possible. Tried doing this:
if (nodes.Any(n => n["Checked"] == false)) ......
Hi All
I'm setting the DataSource of an ASP.NET repeater as follows:
rptTargets.DataSource = from t in DB.SalesTargets select new { t.Target, t.SalesRep.RepName };
Now, in the repeater's OnDataBound event, how can I retrieve the RepName and Target properties from the anonymous type contained in e.Item.DataItem?
Many Thanks
...
I have a anonymous class:
var someAnonymousClass = new
{
SomeInt = 25,
SomeString = "Hello anonymous Classes!",
SomeDate = DateTime.Now
};
Is there anyway to attach Attributes to this class? Reflection, other? I was really hoping for something like this:
var someAnonymousClass = new
{
[MyAttribute()]
SomeInt = 2...