linq

Retrieve and print data from dynamic sql query with linq

I have some existing code that retrieves data from a database using ADO.NET that I want to convert to linq. What the code does is receives an SQL query via command line, executes it, returns the rows and their column names, then prints them to the screen. I would like to know how to write this code in linq. The ENTIRE sql query MUST...

LINQ: Using AssociateWith and Distinct together

I haven't found a way to use these two elements together. Here is my issue: A web page has many bookmarks. A user owns a bookmark. A user can bookmark the same page multiple times (for my purposes). What I want is a list of the distinct users who have bookmarked a page. I'm trying to use the LoadWith() and AssociateWith() methods of...

Why does simple array and Linq generate VerificationException: Operation could destabilize the runtime

A very simple ?: operator in C#, combined with a simple array and LINQ (to Objects) call to Reverse() is apparently enough to cause the exception "System.Security.VerificationException: Operation could destabilize the runtime." when run on an ASP.NET web site running with "High" trust (note that "Full" is the default) Here is the code, ...

Linq to Sql: SubmitChanges() adds more objects to database then I've attached

I have the problem that when calling SubmitChanges() objects that have not been attached to a collection or added using InsertOnSubmit(), are still being inserted into the database. I read online that when assigning an object to a property that represents a foreign key, this object is automatically added to the collection of objects to ...

Any way to get the size attribute from LINQ generated class members ?

I would like to avoid to specify manually maxlength attributes for all form input elements, and instead to use size information from the Data Model if possible: e.g. <%= Html.TextBox("Titel", ViewData.Model.Titel, (object)new { @maxlength = "10" })%> would it be possible "translate" the DbType Attribute in the LINQ class ? [Column(S...

Table Filed

hi My code that can get tablename in linq query is: Dim TY As Type = (From T In DB.Mapping.GetTables() Where T.TableName = tableN Select T.RowType.Type).SingleOrDefault Dim Table As ITable = DB.GetTable(TY) Dim mq = From t In Table Select t tableN get from another form. I w...

Linq - sum child field value when child records query ganareted by diffrent func

Hi, I have order - items tables. so I want to display on some grid all the orders info including a col like total_items There is a premetive working way. like this: TotalQuantity = (from i in _db.ProposaItems where i.ProposaID == p.ProposaID select i) .Sum(q => q.Quantity) But this is not the way I want. I want to use 2 func...

scala -> use .net (linq) and java (various frameworks) in the same program?

Hi, Newbie here...can I write one program which incorporates .NET LINQ and also various Java frameworks in the same scala program? Or when I compile, at that time the decision is made either one or the other, .NET or Java Thanks. ...

Official LINQ Extension Methods

With .NET 3.5 a large amount of extension methods were added to the core base of code. I've noticed that in MSDN, IEnumerable<> etc have a section on Extension methods that have been added. Is there a list of ALL the extension methods that have been added for reference? EDIT Thanks for the answers but I'm looking for a full list, not ...

LinqToSQL Select and SelectMany vs Join

Are Select and SelectMany preferrable to Joins? The reason I'm wondering is because I use LinqPad and in one section there are comments that say: // Note: before delving into this section, make sure you've read the preceding two // sections: Select and SelectMany. The Join operators are actually unnecessary // in LINQ to SQL, and the e...

Multiple LinqToSQL queries and performance

Does something like this affect performance badly? var myQuery = from c in Customers select c; var filter1 = from c in myQuery where c.ID > 2 select c; myQuery = filter1; var filter2 = from c in myQuery where c.Name.Contains("r") select c; myQuery = filter2; When I do this it seems to only do the actual query at the end, not on ev...

Linq to SQL object child properties in GridView

For example, in my WCF, if I have a Customer table and an Order table that have an association to each other on Customer ID. I want to get the Count of the number of Orders for each Customer. In regular VB code I can just do this: Dim CustID As Integer = 1234 Dim cust As New MyService.Customer() cust = cust.GetCustomer(CustID) Respons...

Empty while loop with linq/lamba expression

Where I work we're still on .Net 2.0, but I'm somewhat familiar with the 3.0/3.5 stuff. I wanted to get some practice using linq/lambda expression in C# so I wrote a simple Sudoku solver using a lot of generic List<T> and lambda expressions with the aggregate methods it provides. In my solver, I have this at the top of the solver algor...

How can an object-oriented programmer get his/her head around database-driven programming?

I have been programming in C# and Java for a little over a year and have a decent grasp of object oriented programming, but my new side project requires a database-driven model. I'm using C# and Linq which seems to be a very powerful tool but I'm having trouble with designing a database around my object oriented approach. My two main qu...

LINQ + lightweight database: which db should I choose?

I'm starting up a new web application. It's going to be hosted on a service that charges extra for SQL Server and frankly I don't think the site needs that much of a database. Right now the data model is 5 tables. And I'll be amazed if the largest table ever goes of 10k records. So I'd like to keep the db lightweight. SQLite piqued my ...

Linq to SQl, select same column from multiple tables

I've been trying to develop a linq query that returns the ItemNumber column of all my tables in the database, but so far I haven't been able to do it successfully. Basically I have a table for each kind of hardware component in a computer, and each table has a ItemNumber column. I need to query all of the tables in one bang, and return ...

Operation could destabilize the runtime: LinqToSQL

Despite this being one of the best error messages I've ever seen (second only to, "This operation could destabilize the rent in the space-time continuum"), it's also one of the most frustrating. I have developed an ASP.NET MVC site which works perfectly through VS2008. It works perfectly hosted on a local IIS7 server (Win2008Server & W...

Is it possible to evaluate a string containing valid LINQ dynamically / at runtime?

The basic idea is to take a string and evaluate it against an XML File (or any LINQed provider) I found this LINQ Dynamic Query Library. Just had a cursory glance at the documentation which is a single page in the download bundle. This seems to be adding extension methods to parameterize parts of the LINQ Query. Does anyone know if this...

What is the best local sql database for a .net client application?

I am working on an application that needs to use a local sql database. The database needs to be encapsulated in a file because they need to be able to easily move the data accross the network, onto a usb stick, burned onto a cd/dvd, etc. Our older apps all used access, which has worked great for us, but I'd like to use the newer .net t...

Initialization of var in C#

public IEnumerable <Country> ListPopulation() { foreach(var continent in Continents) { var ids = context.continentTable .where(y=>y.Name == continent.name) .select(x=>x.countryId) } return GetPopulation(ids);// ids is not available here } Public IEnumerable<Country>GetPopulation(IQueryable<int> idnumbers) { } /...