This is what i have now as a very basic search:
var Results = from p in dx.Listings select p;
if (CategoryId > 0) Results = Results.Where(p => p.CategoryId == CategoryId);
if (SuburbId > 0) Results = Results.Where(p => p.SuburbId == SuburbId);
var OrderedResults = Results.OrderByDescending(p => p.ListingType);
OrderedResults = OrderedRe...
Hello,
I can't figure out why my code just taking the first tag and not the rest.
var xml = XDocument.Load(HttpContext.Current.Server.MapPath("~/App_Data/Themes.xml"));
var q = from f in xml.Descendants("themes")
select new ThemesItem
{
Name = f.Element("theme").Element("name").Value,
Descripti...
Hi,
What's the easiest way to get a LINQ query (from an SQL database - does that matter?) to order strings naturally?
For example, I'm currently getting these results:
Project 1
Project 10
Project 2
What I'd like is to see is this:
Project 1
Project 2
Project 10
The query I'm using is this:
return from p in dataContext.Project...
I have below a collection of rows and each row consists of productid, unitid, countryid.
I need to find the details for each row in the corresponding tables (products, units, country)
for product - select product name, updatedby
for unitid - select unit name , updatedby
for countryid - select countryname, uploadby
and returning...
I'm currently using a single query in two places to get a row from a database.
BlogPost post = (from p in dc.BlogPosts
where p.BlogPostID == ID
select p).Single();
The query is fine when retrieving the row to put data in to the text boxes, but it returns an error "Sequence contains no elements" when u...
Say that i have a generic dictionary with data like this (I hope the notation is clear here):
{
"param1" => "value1",
"param2" => "value2",
"param3" => "value3"
}
I'm trying to use the Enumerable.Aggregate function to fold over each entry in the dictionary and output something like this:
"/param1= value1; /param2=value2; /p...
Let's say we have a collection of Person objects
class Person
{
public string PersonName {get;set;}
public string PersonAddress {get;set;}
}
And somewhere in the code defined collection
List<Person> pesonsList = new List<Person>();
We need to have a filter that need to filter the collection and return the result to...
How would I convert this kind of expression in VB.NET? I'm stomped!
bool exists=repo.Exists<Post>(x=>x.Title=="My Title");
This is from the SubSonic docs here: http://subsonicproject.com/docs/Using_SimpleRepository
Thanks in advance!
...
for clarity lets say we have students and classes, its a many to many relationship.
I have a Dictionary where the key is the student id and the Enumerable is a collection of classes(say we just have the id ) and I want to revert this to a Dictionary of classId, students
is there a way to do this with Linq? I can think of a way to do th...
I have the following code snippet:
var matchingAuthors = from authors in DB.AuthorTable
where m_authors.Keys.Contains(authors.AuthorId)
select authors;
foreach (AuthorTableEntry author in matchingAuthors)
{
....
}
where m_authors is a Dictionary containing th...
I´m trying to use an external XML file to map the output from a stored procedure into an instance of a class. The problem is that my class is of a generic type:
public class MyValue<T>
{
public T Value
{
get;
set;
}
}
Searching through a lot of blogs an articles I've managed to get this:
<?xml version="1.0" encoding="ut...
using the linqtemplates, I tried getting the linq syntax close to what is in the docs
var query = from c in db.CountyLookups
join s in db.StateLookUps on
c.StateLookupID equals
s.StateLookupID
where c.Name2 == countyName &&
s.Abbr == stateAbbr
select new
{
Latitude = c.Latitude,
Longitude...
Hello
I have 3 related tables in my employee.dbml
Emp dept Zone
empId deptID ZoneID
empName deptName ZoneType
empage deptID
empzone
deptID
Now how do I get ZoneType by passing empid in a query in linQ
Please help
...
Hi how do you do joins in linq to sql?
I see they have the key word join and group join but what kind of joins are they?
Left, Right, Cross, Inner?
Also how do I select certain columns once I am done?
Like
Select Column1, Column2
From Table A;
Either query or method syntax is fine. I still can't decide what I like better each seem...
Consider the following snippet of code:
// get number of sheep in DataTable by counting UID's
Double n = DataTableContainingSheep.AsEnumerable().Sum(r => (Int32)r["sheepId"])
What I if want to count only the black sheep in the DataTable? Is there any way I can fit a select-clause into the Sum() function?
...
Dear ladies and sirs.
Does anyone know of an existing solution to translate a LINQ Expression to HQL statement?
Thanks in advance to all the good samaritans out there.
P.S.
We already use Linq to NHibernate. However, it only works for select statements, whereas HQL is good for other statement kinds, like delete. So, Linq to NHibernat...
I have a xml structure like this:
<Items>
<Configuration>
<ConfigurationSetting>Setting1</ConfigurationSetting>
<ConfigurationSetting>Setting2</ConfigurationSetting>
</Configuration>
<MetaData>
...
</MetaData>
<Group>
<GroupType>MyType1</GroupType>
<GroupType>MyType2</GroupType>
...
I have two arrays :
string[] Group = { "A", null, "B", null, "C", null };
string[] combination = { "C#", "Java", null, "C++", null };
i wish to return all possible combinations like
{ {"A","C#"} , {"A","Java"} , {"A",C++"},{"B","C#"},............ }
(null should be ignored).
using LINQ.
Help please.
...
OK, I asked for how to return a Linq query results as XML, and I got the answer here.
But there's one little problem: the results do not get grouped logically within the XML. For example:
XElement xml = new XElement("States",
from s in MyStates
from cy in s.Counties
from c in cy.Cities
where s.Code == "NY"
orderby s.Code, cy...
I've received a project for internal use. My application has to store about 100 rows of meta data of a game and each row has about 15 fields maximum. Fields can be game name, game category, maker, source code path, etc. I will most likely have to join about 5-10 tables for each row of record. Only a few people are using it and will recei...