linq-to-sql

LINQ: Difference between 'Select c' and 'Select new (c...'

Hi, What is difference between these two statements: var result = from c in context.CustomerEntities join p in context.ProjectEntities on c.Pk equals p.CustomerPk where p.Entered > DateTime.Now.AddDays(-15) select c; and var result = from c in context.CustomerEntities join p in context.ProjectEntities on c.Pk equals p.Customer...

Insert record into db using linq2sql/datacontext

Hi there, I am trying to insert a standard record into my db using linq2db, but i keep seeing examples to ADD method which i don't appear to have ... what i have currently is the following, as you can see i have my datacontext.... (no add method) ... the Reservation class is a separate class i created as a DTO - i presume this is correc...

Does linq and nhibernate return the same type of collection?

Hi, If I design my db layer so I can swap it between a linq-to-sql or nhibernate implementation, I have to code against an interface. This means the return type between both linq and nhibernate have to be the same i.e. List etc. Is the list type the same? ...

Return a count with linq-to-sql

Hi, I want to return a count of new users since a specific date. Users table has: UserID, username, dateJoined. SELECT COUNT(USERID) FROM Users where dateJoined > @date How would this look in linq-to-sql? Can you use the keyword COUNT? ...

Why does it take so long to get an empty resultset in linqtosql?

I'm running the following query on my database, which generates a sql query I know returns 0 results and when run in sql management studio takes less than a second to return. var query = (from item in db.Table where item.Field == FieldValue // Field is not the primary key but is indexed from other in item.Assoc...

Using linq2SQL to return a 1 to many relationship?

Hi there, is there a good way of of returning a 1 to many relationship from linq2sql, probably needs some explanation ! :-) Basically i have a table that has invoices and another table that is invoice details.. I have my linq2sql classes that were automatically created using linq2sql designer ... So to return the query where invoice ...

Linq to Entity - How to relate an entity to a store procedure

Hello Everyone, I have an entity table that is mapped to stored procedures in order to do all of the CRUD operations. The retrieval procedures mapped to this table mirror the properties of the table as they should. This same entity table has a one-to-reference with a lookup table. I need to be able to access that lookup tables proper...

LINQ to SQL - Bulk Insert Using VB

Anyone have some good examples (newb worthy) of what bulk inserting should look like or a great way to explain it, utilizing the whole LINQ to SQL method? I've got a DB with about 7 tables I'm trying to link some .net pages to and as much as I can qry most of these tables, I'm having a heck of a time inserting into them. One complex sc...

Linq Repository pattern "Specified cast is not valid" Error

Hi, I have the following classes (I've trimmed the code): public class SqlWeightTrackerRepository : IWeightTrackerRepository { private Table<WeightTracker> m_weightTrackerTable; //... constructor + other code here public IQueryable<WeightTracker> WeightTracker { get { return m_weightTrackerTable; } } } //...

LINQ to SQL and the DBML file - multiple database development

Hello. The way I develop may not be correct, any advice welcome. At the moment I have a WPF application that uses a SQL2008 database. I have a copy of the database on a laptop and on my home machine. My application is versioned using SVN and I am obviously able go from the work laptop to the home machine and update/commit as required to...

Using LINQ2SQL and MVC for wizard-type save functionality

Hi, I have an ASP.NET MVC application that uses LINQ2SQL as the database layer. I can save data back to the database no problem but I've came across a few issues when trying to save using a wizard-type scenario where data is collected over a few different forms but not saved to the database until the last form "Save" button is clicked....

Why ASP.NET MVC favorites Linq to SQL over LINQ to Entities?

The question is in the title. ...

Linq to Sql: Can the DataContext instance return collections that include pending changes?

Consider the following code block: using (PlayersDataContext context = new PlayersDataContext()) { Console.WriteLine(context.Players.Count()); // will output 'x' context.Players.InsertOnSubmit(new Player {FirstName = "Vince", LastName = "Young"}); Console.WriteLine(context.Players.Count()); // will also output 'x'; but I'd l...

LINQ Inserts without IDENTITY column

Hello I'm using LINQ, but my database tables do not have an IDENTITY column (although they are using a surrogate Primary Key ID column) Can this work? To get the identity values for a table, there is a stored procedure called GetIDValueForOrangeTable(), which looks at a SystemValues table and increments the ID therein. Is there any ...

how do you handle a case when in a table you got a foreign key that cannot be null?

I have a case where I have a linq2sql dbml with 2 table in it let simplify this by: Table1 id int not null fkid int not null (to table2.id) and Table2 id int not null v1 bit not null in the generated dbml, fkid is not the type nullable and by default it's value is 0 but in table2, I don't have an id 0 when i'm trying to insert a...

"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."

I have a fairly complex Linq query: var q = from eiods in LinqUtils.GetTable<EIOfficialDesignee>() let eiodent = eiods.Entity join tel in LinqUtils.GetTable<EntityTelephone>() on new { EntityID = eiodent.ID, TelephoneType = EntityTelephone.TTelephone.Office } equals new { tel.EntityID, tel.TelephoneType } ...

How to run Integration Testing on DB through repositories with LINQ2SQL?

How do you go about integration testing your database through your domain layer/model (repositories) that uses LINQ 2 SQL in the implementation and leave the DB as you found it? In other words, the ideal world of unit testing the DB, the integration test would leave the DB as it found it. Are there tools out there that will handle this...

Spring.Net support for Linq2SQL

May I know whether Spring.Net has built in support for Linq2SQL? Someone on Spring.Net forum mentioned there is a bridge for NHibernate. However, I might not use NHibernate at all. I am looking for direct support for Linq2Sql. If I am using TxScopeTransactionManager and apply attribute based transaction to a business method which contai...

Temporary tables, sessions and logging in SQL Server?

I've read --while trying to figure this out-- that with temporary tables there's the notion of a session in SQL Server. However, I have not been able to find any documentation regarding what exactly constitutes as a SQL Server session. With this information, I'd like to implement some basic logging functionality. My problem is that I ...

Linq "Could not translate expression... into SQL and could not treat it as a local expression."

I started out with this question, which I sort of answered there, and now I'm asking the more fundamental question here. I've simplified the query down to this: var q = from ent in LinqUtils.GetTable<Entity>() from tel in ent.Telephones.DefaultIfEmpty() select new { Name = ent.FormattedName, Tel = te...