linq-to-sql

Get generated tablename for an entity?

If I have the type of my entity generated by linq2sql, how can I get the name of the table the entity belongs to? I want the tablename generated by linq2sql not the database table name. ...

Converting Rows to Columns without loop

Hey, I have a situation where i have data like following User1 Address1 HomeAddress Address1Value User1 Address2 WorkAddress Address2Value User1 Phone1 HomePhone Phone1Value User1 Phone2 WorkPhone Phone2Value User2 Address1 HomeAddress Address1Value User2 Address2 WorkAddress ...

No result in LINQ query gives Object reference not set to an instance of an object in IF ELSE statement.

I have the following code: DataClasses1DataContext db = new DataClasses1DataContext(); var UserInfo = db.Users.FirstOrDefault(u => u.Email == TextBox1.Text); if (UserInfo.Email != null) { Label2.Text = "Email is not null"; } else { Label2.Text = "Email is ...

Use Take() to get a limited number of results but also get the potential total

Given the following... int maxResults = 25; string code = "Thailand"; var q = from i in images where i.component_code == code select i; var images = q.OrderByDescending(x => x.image_rating).Take(maxResults); if (images.Count() > 0) { ... lblResult = string.Format("Viewing {0} Images Of A Possible {1}", images.Count(), ?); } ...

LINQ Stored Procedure DATETIME NULL

I got this errormessage when I use Linq and and stored procedure as follow. I got this message when the DateTime parameter is NULL. How will I do to solve this? Errormessage Serverfel i tillämpningsprogrammet. SqlDateTime-spill: Det måste vara mellan 1/1/1753 12:00:00 AM och 12/31/9999 11:59:59 PM. Codeblock in C# protected void Butt...

Inserting data in a table with a auto increment key C# .NET Linq to SQL

I want to input data into my table (sql 2008) using linq to sql: public static bool saveEmail(Emailadressen email) { TBL_Emailadressen saveMail = new TBL_Emailadressen(); destil_loterijDataContext db = new destil_loterijDataContext(); saveMail.naam = email.naam; saveMail.emailadres = email.emai...

LINQ to SQL Classes & Datacontext are not created

Afternoon all This is driving me nuts. For no apparent reason (of course there must be one), my web project will no longer generate LINQ to SQL classes/data contexts!!! I am going about the usual routine of right clicking the project, adding new item, selected LINQ to SQL classes, then dragging over a table from Server Explorer, savin...

How to get next object in IEnumberable / IQueryable if ID key is not consistent?

Hello everybody, After hacking more on my current app - once again, I am running into an issue which kills some of the joy I expected from my domain model. The problem here is that the aggregate root / most important class in my domain model doesn't have consistent ID values for its entries. (E.g messed up : 1..3..5..12..150..157.. an...

LINQ Equivalent for SQL BETWEEN

Is there a LINQ To SQL equivalent to the SQL between keyword? Do I just need to And both comparisons? SELECT first_name, last_name FROM people WHERE last_name between 'Smith' and 'Thompson' ...

Aggregate functions with a left outer join in LINQ to Entities

I've been looking through related LINQ questions here trying to figure this one out, but I'm having some trouble converting a SQL query of mine to the equivalent LINQ to Entities version. select companies.CommpanyName, job.Position, count(offers.jobID) As Offered, job.Openings, job.Filled from jobs left outer...

Does Adding "TOP 1" to a sql statement increase performance signficantly?

In a SQL query, does adding "TOP 1" to SELECT TOP 1 [values] FROM [TABLE] where [TABLE].Value = "ABC" give me a performance increase, when I know there is only one of those records? Specifically I'm thinking about LinqToSql and the difference between the methods .Single(...) and .First(...), where .First(...) adds the TOP 1 to the g...

Don't save an associatied object in Linq To Sql.

Hi. I have an entity (Address) that has a assosiated entity (Country). <Table Name="dbo.Address" Member="Address"> <Type Name="TS.Club.Domain.Model.ValueObject.Address"> <Column Name="Identifier" Member="Identifier" DbType="UniqueIdentifier NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="false" AutoSync="OnInsert" /> ...

LINQ to SQL Pagination and COUNT(*)

I'm using the PagedList class in my web application that many of you might be familiar with if you have been doing anything with ASP.NET MVC and LINQ to SQL. It has been blogged about by Rob Conery, and a similar incarnation was included in things like Nerd Dinner, etc. It works great, but my DBA has raised concerns about potential fut...

Dynamic table generation through LINQ To SQL. How to change ITable to Table?

Hi Guys, I am working on a windows application. I just wanted to generalize the code for all the master forms. So I decided to create a user control with specific containers. We are using LINQ to SQL and I wanted to pass on a table name and get the corresponding data. I have a BindingSource and a BindingNavigator along with a DataGridVi...

Hacker News style ordering algorithm in Linq-To-SQL

According to this site the ordering algorithm for hacker news goes something like this: (p - 1) / (t + 2)^1.5 Description: Votes divided by age factor p = votes (points) from users. t = time since submission in hours. p is subtracted by 1 to negate submitters vote. age factor is (time since submission in hou...

linq to sql - Inserting a class with null reference

Hi all, I am using linq to sql for a quick project of mine (if I understood correctly, linq to sql is dead... right?). Anyhows, problem occurs in the following situation: I've got a class (table) that references other table. I don't load all tables that the first table is related to. When I try inserting the object, which doesn't have...

LINQ to SQL datacontext update after changing SQL Server name

In a WPF application I use LINQ to SQL, SQL Server 2008. SQL Server computer was replaced and SQL Server was installed under instance name not the same as before. Database was restored under the same name as before. The new connection string was added to the application. But it appeared that it is impossible for the application to con...

Performance bottleneck - Linq to SQL or the database - how do I tell?

Hi, I am currently trying to ring more performance out of my reporting website which uses linq to sql and an sql server express 2008 database. I am finding that as I now approach a million rows in on of my more 'ugly' tables that performance is becoming a real issue, with one report in particular taking 3 minutes to generate. Essential...

Are multiple table updates in one linq 2 sql datacontext session transactional?

I can't seem to get an answer through google about this. If I perform updates to multiple entities at one time, attach them all to context, call Submit() and one of the updates to the entities fails, do all the changes get rolled back? For example, in my asp.net application I have a note and a note revision table. In my asp.net applic...

What are the advantages or disadvantages of using dbml for linq2sql queries?

I am currently reading Pro Asp.Net MVC, and they are building all of their linq2sql entity classes by hand, and mapping them with the linq mapping attributes. However, everyone else I see (from google searches) talking about linq 2 sql seem to be using the visual designer for building all of their entities. Which is the preferred way t...