linq-to-sql

Windows App and SQL Server

What's the best practice for a windows app connecting to a SQL Server that is hosted in the internet? I'm currently using an IP based connection string with SQL authentication, nothing special. However, some clients cannot connect using port 1433 and I'm assuming that the whole approach has some security concerns. ...

Is it possible to make LinQ "understand" a classic SQL query??

Hi everyone! Is it possible to make LinQ to SQL read and understand a pure SQL query sucha as "SELECT * from myTable"?? My boss asked me to write directly to database the pure SQL querys in a certain table and this table will have a field named "typeOfSelect", for example. And, in my application, I will have to read this field "typeO...

Linq to Sql, how to check if a given table/class is in the changeset of the DataContext

Hi, I'm parsing a XML-file using LinqToXSD. I'm using Linq to SQL to insert the elements in the XML in corresponding tables in a database. I'm inserting many different tables/elements in the DataContext using DB.<tables>.InsertOnSubmit(table); where tables could be any of about 75 different tables. The XML is full of duplicates, a...

Linq to Sql - return selected specified columns

I would like to select only few columns from a certain (Blobs) table. I have fields like: Id, RowVersion, Size, Signature, Blob, and I want to select only first four. I do it like this: (---> is an error place) public List<BlobDetails> GetAllBlobsNames() { RichTekstModelDataContext dc = new RichTekstModelDataContext(); var ...

Generating Columns in GridView ( C#, LINQ )

The situation is, that i need to create table in grid view looking like this: ----------| ID---|---Name--|--1/2002--|--2/2002--|--1/2003--|........| 2/2009 | Cust1--| Cust2--| : : I have two tables in db - Customers and orders, throught LINQ to SQL DataContext ID and Name of the customers i´m getting from a simple query var custInfo = ...

LINQtoSQL Retreiving a table according to the values of another table where it has a many to many relationship with

I have the following three tables: With LinqToSql I would like to retreive a list of InventoryItems where (pointsName="Level" AND pointsValue <= maxStoreLevel) AND pointsName="Buy Price" and Note that maxStoreLevel is an Integer and it is the value of the points row that has pointsName = "Level". Since you can't use a where inside...

C# Linq-to-Sql - Should DataContext be disposed using IDisposable

I have several methods that deal with DB and all of them start by calling FaierDbDataContext db = new FaierDbDataContext(); Since the Linq2Sql DataContext object implements IDisposable, should this be used with "using"? using (FaierDbDataContext db = new FaierDbDataContext()) { // use db here } What are the implications of usin...

Linq to SQL, Ajax postbacks, and page state in ASP.NET

This has to be a frequent question, but not on SO yet, so it seems. I am using Linq to SQL for an application that allows a variety of data changes to my in-memory model, and the changes will then get placed into a queue for asynchonous processing. So, I am not worried about updates (yet). Changes to various parts of the data can be made...

Linq Intersect(...).Any() inside of a Where clause throws NotSupportedException

Whenever the tags argument is not empty I get a NotSupportedException: Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator. [WebMethod] public static object GetAnswersForSurvey(string surveyName, int? surveyYear, IEnumerable<string> tags, IEnumerable<string> benchmarks) { I...

How to choose a data access method in ASP.NET MVC?

I've been programming in C# 2.0 WinForms for a while now. I'm starting to get into ASP.NET and the new MVC framework and the new features of C# 3.5. I've only read a little on LINQ to SQL but have made a few test apps to try it out. In my WinForms apps, I usually had some sort of data access layer, and wrote all the SQL myself. Of course...

Linq to SQL DateTime values are local (Kind=Unspecified) - How do I make it UTC?

Isn't there a (simple) way to tell Linq To SQL classes that a particular DateTime property should be considered as UTC (i.e. having the Kind property of the DateTime type to be Utc by default), or is there a 'clean' workaround? The time zone on my app-server is not the same as the SQL 2005 Server (cannot change any), and none is UTC. Wh...

SqlMetal generating garbage association names

Why is SqlMetal messing up the Association names. For e.g. in my 'TextMessage' table i have two columns referencing the 'ApplicationUser' table. 'SenderUserId' and 'RecipientUserId' When I run SqlMetal and look at my 'ApplicationUser' class For 'RecipientUserId' it generates: [Association(Name="FK__TextMessa__Recip__72910220", Storage...

C# Linq Guid Anonymous Type Problem

Hello, I have a linq query which returns the ID of a question based on the questions text. This ID is then needed to be used to relate a date in a date table to that particular question. The question is already stored and the date is stored at a different time. The problem is that the query returns the questionID as an anonymous type a...

Inserting image over 3mb via linq-to-sql

New day, new problem :-) Code: Client Side: void abw_Closed(object sender, EventArgs e) { DbServiceClient sc = new DbServiceClient(); abw = (AddBlobWindow)sender; fi = ((AddBlobWindow)sender).fi; if ((bool)((AddBlobWindow)sender).DialogResult) { blob = new Blob(); binBlob = new Binary(); bina...

Export an IQueryable Collection to Excel

I have a huge IQueryable that I want to export directly to Excel for data dumps, how would I do this? I was trying to put it into a GridView and export from there, which works if I use only a chunk of the data, but if I use the whole IQueryable, nothing happens. This is a table with 4k rows and each row has 70 or so columns. Edit: CSV...

how to get second record in linq to sql

I have a exchange rate table. I need to get current rate and previous rate and then compare results. I can get first record using FirstOrDefault. When i using ElementAtOrDefault,error show "The query operator 'ElementAtOrDefault' is not supported". How can i get second record? ...

How to search a varchar field, using LINQ, to build a list of recommendations

I am trying to construct a LINQ query, with expression trees, to do the following: I have a field in my ItemCode table called Labels, an example of the data contained in this field is "lamps lighting chandelier". I want to allow the user to type in some text, i.e. "Red Lamp", and be able to search the Labels field, of the ItemCode, tab...

Linq to Sql compared to NHibernate mapping options

Hi all, I'm pretty much a newbie and I need to dig into this matter to write some college article so I need some bootstrap. Here and there I read that NHibernate offers much more flexibility (compared with L2S) in mapping domain model to database. Can you write down some hints what should I explore? ...

Get a random row with LINQToSQL

Is there a way to return a random row from a table using LINQToSQL? ...

Accessing info from FK-related tables with LINQ

I am working on an employee-scheduling system. I think I have the database setup pretty well, and have run into a snag on pulling the data for my database and getting it onto the page. I am using LINQ to make things easy on myself. Here is the Object Relational Map. Here is my Linq select statement: protected void LinqSelecting(object...