linq

Getting list of cities and countries from a SQL Table

I have a SQL table where in each row I store the country and the city of a things location. For example: record1, New York, USA record2, Rome, Italy record3, Milano, Italy record3, Birghiman, UK record4, London, UK record5, London, UK record6, London, UK record7, Birmingham, UK I would like to generate a list that is ordered by cou...

LINQ for beginners

Hello, I love C#,I love the framework and I also love to learn as much as possible.Today I began to read articles about LINQ in C# and I couldn't find anything good for a beginner that never worked with SQL in his life. I found this article very helpful and I understood small parts of it,but I'd like to get more examples. After readin...

Adding a default SelectListItem

public IEnumerable<SelectListItem> GetList(int? ID) { return from s in db.List orderby s.Descript select new SelectListItem { Text = s.Descript, Value = s.ID.ToString(), Selected = (s.ID == ID) }; } I return the above to a vi...

.net, SQLDataTableAdapters question

I have a sql query method using SQL data table adapters in .xsd file and need to be able to dynamically change the connection string to that method in the code behind. I can't figure out how to access the methods properties from code behind. method is IsValidDock(), simply checks database for a particular dock number and returns bool....

Need to retrieve List of items containing subitems matched with another List

Situation: I have some persons with certain skills and they can/might belong to more than one area. The skills are linked in a seperate table, so are the areas. I get the people list from selecting all persons with a match on each skill and add them to a list where I can use Distinct() to make sure that they dont show up twice. Result...

Linq Joining IEnumerable(Of Struct) to IEnumerable(of object)

Hi, With class RoleRecord (Guid RoleId, string RoleName,...) I am trying to get a new list of Name where the RoleId matches a list of Guid IEnumerable<RoleRecord> roles; IEnumerable<Guid> roleIds; I was thinking about avoiding the nested for loops, and along the lines of : var query = from rowA in roles ...

Linq version of SQL "IN" statement

I have the following 3 tables as part of a simple "item tagging" schema: ==Items== ItemId int Brand varchar Name varchar Price money Condition varchar Description varchar Active bit ==Tags== TagId int Name varchar Active bit ==TagMap== TagMapId int TagId int (fk) ItemId int (fk) Active bit I want to writ...

How do I project to a dictionary with a custom type using Linq to SQL?

Hi, I am attempting to use Linq to project each row from a DB query into a dictionary that has a custom type as its value. I am unsure of the LINQ syntax to do this? This is my current attempt (which doesn't compile, but should demonstrate what I am trying to do). I am having trouble with the 'select new...' part. public class MyClas...

When using a LINQ Where clause on a Dictionary, how can I return a dictionary of the same type?

I'm currently using the following code to achieve this, but is seems there should be something better... suggestions? It just seems to me there should be a way to skip the foreach... Dictionary<string,string> getValidIds(Dictionary<string,string> SalesPersons,List<string> ids) { Dictionary<string,string> o = new Dictionary<string,...

Linq To Sql Search Multiple Columns and Multiple Words

I am trying to do an autocomplete search using a webservice and Linq To Sql to access the database. Here is my code. This returns results that match any of the search terms, I would like to modify this so each result contains all of the search terms. I'm aware that SQL full text search is probably the most elegant solution, but I'd lik...

How to handle programmatic addition of fields?

Yesterday, I asked this question regarding best practices for a simple information retrieval system I am beginning to work on. Today, my customer asked me if it is possible to allow them to add fields to the primary entity at a later date using the administration interface. That is, the application allows you to search across one databa...

Dynamically building LINQ query using OR operator in VB

I need to build a dynamic linq query with or operators. I have seen PredicateBuilder but that is in C# and my project is in VB. Basically I need to build a WHERE clause similar to this: Where((this = 1 AND that = 2) OR (this = 1 AND that = 4) OR (this = 2 AND that = 4)) but the problem is the number will have to be determined dynami...

Linq To SQL Attach/Refresh Entity Object

In Linq To Sql, when updating one of my entities, Faculty, I am creating a new instance of the Faculty object, then initializing some of the properties with values supplied by the user. If I attach this new object to the entity set, and submit changes, the properties that I didn't set take on the default value of whatever datatype they ...

Simulating Cross Context Joins--LINQ/C#

Here's the issue: I have 2 data contexts that I would like to do a join on. Now I know that LINQ doesn't allow joins from one context to another, and I know that 2 possible solutions would be to either create a single datacontext or to have 2 seperate queries (which is what I'm doing for now). However what I would like to do is to "sim...

Access xml using Linq when xsd is available

I have an xml file containing a lot of data. The structure of the file derives from several formats I have the xsd files for. They all merge to the schema that completes the view. What is the best way accessing the xml file using linq when I need to get all data and work with it? ...

Linq to SQL DataContext Lifetime Management Issue

I read Rick Strahl's article about ways to deal with the data context. My DBML is inside a class library, I keep my data context open by creating a static Current method in a separate custom partial class within library. public partial class DataContext { public static DataContext Current { get { Dat...

Good table editor for MS SQL Server?

I have MS SQL Management Studio for editing table data, and it is doesn't have a good usability. I need to edit some hundred rows like in Excel, being able to order columns to easy editing process (SQL Mgmt only has 'Open table' feature, without ordering columns, updates diferent than that is only possible using UPDATE SQL code). LinqPa...

Second "from" statement in LINQ

Hello, I'm new to LINQ,My knowledge on that library is from Jon Skeet's book "C# In Depth 1" I read a lot of tutorials about LINQ in the past days including Skeet's book,but I could never find out a code snippet showing a normal C# code and then the shorter version of that code with LINQ so the reader can understand what does what. My...

LINQ - Where not exists

What is the equivalent of following statement in LINQ: Select t1.appname, t1.julianDte, t1.cat From table1 t1 Where NOT EXISTS ( Select * from table t2 where t1.cat = t2.cat AND t2.julianDte < t1.julianDte ) ...

LINQ - how to convert query syntax to method syntax

I'm fooling around trying to learn the ins an outs of LINQ. I want to convert the following query (which is working correctly) from query syntax to method syntax, but I can't seem to get it right. Can anyone show me the correct way to accomplish that? var logQuery = from entry in xDoc.Descendants("logentry") ...