I've got a number of classes that implement a specific interface (ISearchable) and I'd like to return an IEnumerable of the base type (ISearchable) from a static method, but I'm not sure how to convert it without making intermediate collections.
The code is pretty simple, one of the domain objects' implementations is like so:
public cl...
an extension method on a collection named MeasurementCollection checks if the property Template.Frequency (Enum) of each item has the same value.
public static bool IsQuantized(this MeasurementCollection items)
{
return (from i in items
select i.Template.Frequency)
.Distinct()
...
I am creating my very first larger ASP.NET MVC application. After thinking about the application architecture for some time, I thought I would hear some other opinions.
I am using LINQ-SQL for my data layer. However, I am not planning on using the LINQ objects throughout the application, since I would like some more specific data types ...
Basically I have a collection of objects each implement a member of Type IValueCollection
public interface IValueCollection : IEnumerable<decimal>
{
decimal this[int index] { get; set; }
}
MeasurementCollection.Values is of type IValueCollection.
With the logic below I want to pivot a collection of IValueCollection and wrote the...
I'm getting an array of strings for which I want to see if a certain number of data fields in the domain object have all of those strings. I know the data fields at compile-time but I don't know the size of the array at compile-time.
Is there a way that I can compose a where clause at run-time so that I can do what I'm looking for in a ...
I'm iterating through a smallish (~10GB) table with a foreach / IQueryable and LINQ-to-SQL.
Looks something like this:
using (var conn = new DbEntities() { CommandTimeout = 600*100})
{
var dtable = conn.DailyResults.Where(dr => dr.DailyTransactionTypeID == 1);
foreach (var dailyResult in dtable)
{
//Math here, res...
...I'm a little confused, or unsure about how to deal with errors that arise from LINQ statements. I just love being able to pull one or more items from a collection, based on some criteria... with a single line of code. That's pretty awesome.
But where I'm torn is with the error handling, or the boundary condition checking. If I wan...
I am trying to perform to calculation. I have a donations (d) table that contains Quantity Needed (d.QtyNeeded) and I need to determine the numbers of items still needed by pulling quantity filled (qtyfilled) from the donors table. Not every donation has a donor, so I need a conditional statement to handle nulls so the sum will work. ...
Hi All,
I'm currently investigating ASP.NET MVC 2 and LINQ to SQL. It all looks pretty cool. But I have a few application and development lifecycle issues.
Currently, I design the DB in SqlServer Management Studio.
Then I update my DBML files by deleting and re-importing modified tables.
Issues:
I can't find how to simply update the...
It is possible to get functionality similar to .NET's LINQ in C++? Would this require language extensions or could it be done using some very clever macros? Or even through a tool like Qt's moc (meta-object compiler)? Are there any existing LINQ implementations for C++ and if so, what are they?
...
What's the best approach to call Dispose() on the elements of a sequence?
Suppose there's something like:
IEnumerable<string> locations = ...
var streams = locations.Select ( a => new FileStream ( a , FileMode.Open ) );
var notEmptyStreams = streams.Where ( a => a.Length > 0 );
//from this point on only `notEmptyStreams` will be used/v...
hello,
I am creating project with MVC vs 2010.
I want to use LINQ for queries.
I have created a .dbml file and drag and drop tables on it.
In some online tutorials there are scalar and navigation properties while dealing with table join in designer surface. How to get these properties, shown in designer surface in .dbml file.
Can a...
I need to move sibling nodes before and after certain nodes. Here is the code im working with
<tabs>
<tab>
<name>Overview</name>
</tab>
<tab>
<name>Testing</name>
</tab>
<tab>
<name>Performance</name>
</tab>
<tab>
<name>Braking</name>
</tab>
</tabs>
I woul...
I'd like to make a comma seperated value string with Linq's Aggregate function. Anyone know how to do this?
Given an array of strings like this:
var authors = new string[] {"author 1", "author 2", "author 3"};
How do I get a single string like this author 1, author 2, author 3?
I'm thinking something like authors.Aggregate(author => ...
How to convert
Dictioanry<String,List<String>> into Dictionary<String,String>
i'm having a dictionary like
Dictioanry<String,List<String>>dictOne=new Dictionary<String,List<String>>();
and which containg
Key(String) Value(List<String>)
A a1,a2
B b1,b2
C c1
i ...
i'm having an xml file like
<Root>
<Child Name="A" />
</Root>
i need to check whether the "Child" element have "val" attribute.if yes , and if the value is greater than zero then need to change the value of a Boolean variable into true;
now i'm using like
bool bVal=false
bVal=XDocument.Load(Application.StartupPath+"\\foo.xml")...
string[] names = { "Burke", "Connor", "Frank",
"Albert", "George", "Harris", "David" };
peoples[] people = {
new peoples("Connor",20),
new peoples("John",22),
new peoples("Merry",33),
new peoples("Frank",65),
new peoples("Frank",34),
...
I have an XML
<item id="1">
<item id="1.1">
<item id="1.1.1" />
<item id="1.1.2" />
<item id="1.1.3" />
</item>
<item id="1.2" />
</item>
<item id="2">
<item id="2.1" />
<item id="2.2" />
<item id="2.3" />
</item>
<item id="3" />
I need LINQ to get the first level, without children
<ite...
Basically I have a datakey that I'd like to query from my GridView instead of looping through all the rows and comparing the key of each row. So I was wondering if it was possible to just do a linq query on the gridview (not datatable) and filter with the datakey.
...
I have
string[] pkgratio= "1:2:6".Split(':');
var items = pkgratio.OrderByDescending(x => x);
I want to select the middle value and have come up with this. Is this a correct way to select the second value in an IEnumberable?
pkgratio.Skip(1).Take(1).First();
...