I have a data table that contains a one-to-many self referential relationship:
Plant
{
ID,
Name,
ParentID
}
I'm trying to create a linq query that will tell me the total number of descendants stemming from one Plant.
Example:
I have 5 plants:
One {ID = 1, Name = Pine, Parent = null};// This is the root
Two {ID = 2, Name ...
I have a simple rating application of an Item. There are three main tables:
Item
{
ItemID,
Contents
}
asp_User
{
UserID,
Name
}
Rating
{
RatingID,
ItemID,
UserID,
int Rating
}
I have linq code that reads the items:
var q = from item db.Item
select item;
I would then like to append to q a column ...
Hi,
I am using NHibernate 3 Alpha 2, and I am trying to do the number of posts per month
This is the code I came up with
List<PostMonthFrequency> monthFrequencies = _postRepository
.FindAll()
//.ToList() //<- if included works. however not desired
.OrderByDescending(x => x.PublishedOn)
.GroupBy(x => new {x.PublishedOn....
I have two linq queries that I want to unionize on a common attribute:
One
{
Id,
Name,
Color
}
Two
{
Color,
Cost
}
I want to get the union of One and Two by unionizing on Color? If there is not a Two with a Color that corresponds to One, I want to set Cost to 0 in the output? How do I do this in LINQ?
...
Can NHibernate linq/lambda expressions be compiled so they aren't reevaluate on every use?
...
Sample XML:
<MenuDataResult>
<Items>
<Item>
<ItemType>Submenu</ItemType>
<ItemTitle>Level22</ItemTitle>
<Menu>
<MenuSelected>false</MenuSelected>
<ChildMenuSelected>false</ChildMenuSelected>
</Menu>
</Item>
<Item>
<ItemType>Submenu</ItemType>
<ItemTitle>Level21</ItemTitle...
I have an XML file of the following structure
<Root>
<Child Name="First">
<Data Name="a" val="0"/>
<Data Name="b" val="1"/>
<Data Name="c" val="20"/>
<Data Name="d" val="10"/>
<Data Name="e" val="2"/>
<Data Name="f" val="0"/>
<Data Name="g" val="0"/>
<Data Name="h"...
I have added a partial class to one generated by the Entity Framework. I wanted to add a calculated field that I could bind to my GridView. However, when I try to access the new property, I get an error message that this is a limitation to Entity Framework.
Are there any work arounds to accomplish this?
...
I have a LINQ query, and I want to have a delegate that I can assign the "OrderBy" or "OrderByDescending" methods to. The signature of the "OrderBy" extension method is:
public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector)
Can anyone show me what...
Given the following table structure, how can I use a Linq query to return a list of Category names and the total count of products in that category?
Category
---------
ID
Name
Product
---------
ID
IDCategory
Name
My ideal, return would be:
Clothes 156
Electronics 2149
Utensils 412
Etc.
EDIT:
Thanks for the helpful suggestions, I...
class Program
{
static void Main(string[] args)
{
MyDatabaseEntities entities = new MyDatabaseEntities();
var result = from c in entities.Categories
join p in entities.Products on c.ID equals p.IDCategory
group p by c.Name into g
select new
...
Developing a .net library based on an industry standard. The standard includes data structures and an api for interacting with a server.
I am considering adding a Linq friendly implementation, and to try to either implment or emulate Linq to Entities. The obvious difference is the API is used for CRUD operations, instead of a database ...
I have a simple table like:
| fkId | Item |
---------------
| 1 | A |
| 1 | B |
| 1 | C |
| 1 | D |
| 2 | H |
| 2 | I |
| 3 | Y |
| 3 | Z |
I want a LINQ query that will first count the number of Item's per fkId, and then report the number of fkId's with a given Item-count.
With the sa...
What I have is basically:
public class Object{
public bool IsObjectValid { set; get; }
}
public class MyThing{
public List<Object> Objects { set; get; }
}
What I want to do:
public class ObjectsFiltered{
public List<Object> ValidObjects{
get{
var list = LFs.Sort<_LF> where (IsObjectValid == true);
...
I have created a method in my data context that is mapped to a SQL stored procedure. The method is used in an ASP.NET application, and it is called twice in the lifecycle of a page. It returns the same single object in both cases (i.e. same primary key).
After the 1st call some data changes are made, so on the 2nd call the stored proce...
Hi Guys,
I'm working on a .NET 4 application, C#, Entity Framework 4, SQL Server 2008.
I have a 7 tables in my database, each representing a specific level of location (Country, State, City, Neighborhood, etc).
Now in my Repository I am trying to define an interface contract which has only one Find() method. To do this, I've created ...
I have the following LINQ code:
docTypes = (from c in context.Citizenships join
cdt in context.Citizenship_Document_Types
on c.Country_Code equals cdt.Country_Code
from cd in context.Citizenship_Documents
.Where(cd => cd.Citizenship_Id == c.Citizenship_ID)
...
I declared a 3 X 3 Matrix
int[,] matrix=new int[3,3]
{
{1,2,3},
{4,5,6},
{11,34,56}
};
when i try to enumerate it like
var diagonal = matrix.AsQueryable().Select();
I am unbale to convert it as enumerable collection.How to do that?
...
Hi All,
I am using and EntityDateSource and I add where condition to filter the data at runtime and then bind the grid to the dataSource, but I am getting following error:-
The argument types 'Edm.DateTime' and 'Edm.String' are incompatible for this operation.
Search condition looks like this:-
it.[MyDate]='8/13/2010 00:00:00'
Any...
I would like to count the frequency of words (excluding some keywords) in a string and sort them DESC. So, how can i do it?
In the following string...
This is stackoverflow. I repeat stackoverflow.
Where the excluding keywords are
ExKeywords() ={"i","is"}
the output should be like
stackoverflow
repeat
this
...