linq-to-sql

LINQ to SQL default values

We all know that Linq to SQL (and SQLmetal/exe) is really a "prototype" quality product (it's missing basic features like schema "refresh" and detection of null columns with default value). Is there a way to automatically create my .dbml (similar to LINQ to SQL or SQLmetal) AND have it detect NOT NULL columns that have a default value? ...

Entity Framework/Linq to SQL: Skip & Take

Just curious as to how Skip & Take are supposed to work. I'm getting the results I want to see on the client side, but when I hook up the AnjLab SQL Profiler and look at the SQL that is being executed it looks as though it is querying for and returning the entire set of rows to the client. Is it really returning all the rows then sortin...

How search LINQ with many parametrs in one column?

Hello! For example have this table: Name | BodyType ---------------- John | 1 Ted | 2 Daniel| 3 George| 4 I my app i check "1" "2" and "3" checkbox. And i should find 3 rows (John, Ted, Daniel) and NOT George. How can i get this query in LINQ? (not use where p.BodyType!=4) Use logic OR var all = dataContext.Users; foreach (search...

How LINQ many to many with OR search?

Hello. I have the following table structure: Table Users ID | Name 1 | John 2 | Ted 3 | Alice 4 | Barney and table UserLanguages ID | UserID | Language 1 | 1 | 1 2 | 1 | 5 3 | 2 | 2 4 | 2 | 3 5 | 3 | 3 6 | 4 | 4 7 | 4 | 5 I check languages 2,3 and 4 and I want to get user...

Problem with ExecuteMethodCall

Hi, everyone! I've sql Server 2000 DB which includes Stored Procedure that return Current DateTime. And I've the procedure that call this procedure : [Function(Name = "dbo.spGetDBDateTime")] public ISingleResult<DateTime?> GetDBDateTime() { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMet...

How do I add attributes to properties generated by Linq2Sql in a different partial class

Hello, Let's say I've a partial class generated by Linq2Sql.Let's say the generated class has 2 properties LastName and FirstName. How do I add attributes to its properties using an other partial class? Thanks for helping. ...

Linq repository and GetTable<T>()

I'm following the fairly standard L2S repository pattern, using the following as one of the methods public IEnumerable<T> GetAllByFilter(Func<T, bool> expression) { return _dataContext.GetTable<T>().Where(expression); } I'm a bit miffed to see that the call to GetTable appears to literally get the table, with the Where expressi...

LinqToSql Precompiling queries benefit?

I was looking through the sample LINQ queries provided with LINQPad taken from the C# 4.0 in a Nutshell book, and ran across something I have never used in LINQ to SQL... Compiled Queries. Here is the exact exmaple: // LINQ to SQL lets you precompile queries so that you pay the cost of translating // the query from LINQ into SQL only o...

Linq2sql on different SQL Server Schemas

I have a application which is running in both production and development environments. I would like to utilize the databases better (and save money on my hosting bill) so i want to be able to make my Linq2Sql run on two different schemas (instead of two different databases) (there are ~15 tables in a schema). How to set this up in Linq2S...

How to do a recursive query in Linq2Sql?

I have the following table, MenuItems, in the database: ID ParentID Name --- --------- ----- 1 0 Item 1 2 1 Item 2 3 1 Item 3 4 0 Item 4 5 3 Item 5 I want to write an extension method to get all menu items to the root of the tree. Something like this: public IQueryable<MenuItem> Get...

Why does LINQ to SQL think think that my new object is null when I try to add it to the database?

I am trying to add a record to my database table using LINQ to SQL and ASP.NET MVC 2. The snippet in my controller that populates the LINQ object is this: /* other code removed */ if (ModelState.IsValid) { var stream = new Genesis.Domain.Entities.Stream(); // Handle stream // Is this...

Why is this LINQ so much slower than its SQL counterpart?

I have the below LINQ to SQL method that takes an inordinate amount of time to execute yet its SQL counterpart is quite simple and fast. Am I doing something wrong in the LINQ part? I am just trying to return some data to display, read-only, in a Data Grid. I understand that if the tool doesn't fit don't use it and as such I could j...

[linq] CRUDing composite object using association properties / LINQ2SQL desginer

First of all some notes: 1. As I realize I'm asking for relatively a lot, I shall offer a (humble 50 rep) bounty ASAP, even if I'll get an answer before doing that. 2. I'm noob at this, so any direction would help. 3. I'd like only Linq2Sql designer or association properties solution, as it seems most elegant. 4. this is a follow-up ques...

Is there a secret to using LINQ to SQL to add records when the object has relationships?

I am working in LINQ to SQL, ASP.NET MVC, and C#. I have a repository called genesisRepository to connect to the database. I have a table represented in an object called Stream. It is defined like this: [Table] public class Stream { [HiddenInput(DisplayValue = false)] [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync...

Help converting multi DB SQL Query to LINQ

I have the below SQL Query, which returns what I expect, and I would LIKE to accomplish the same thing in LINQ but so far my results have been less then spectacular. The major hurdle, as I see it, is that the data is coming from 3 separate DB's. I was able to accomplish this in LINQ but it is extremely slow, see here. So, with out fur...

Conditional Linq Queries

I have a dropdownlist which when selected pulls the data out of a database. There are many options in the dropdownlist and one of them is "All". I want that when the user selects the "All" option it should pull everything out of the database. What is a good way to implement this feature? ...

Updates in Linq To Sql

For updating records, instead of querying the context and updating each record individually, we currently use code that does DeleteAllOnSubmit on existing set of rows and InsertAllOnSubmit on new set of rows. This worked fine for majority of our scenarios, as in if the same row (content) is being inserted/deleted, it gets removed even th...

How can I merge two outputs of two Linq queries ?

I'm trying to merge these two object but not totally sure how.. Can you help me merge these two result objects? // // Create Linq Query for all segments in "CognosSecurity" // var userListAuthoritative = (from c in ctx.CognosSecurities where (c.SecurityType == 1 || c.SecurityType == 2) ...

Even Though I check my IEnumerable for null I still get a null exception...why?!

How can line 25 in the code below generate the error that follows? I'm baffled. ProductSuggestions is IEnumerable<Product> ProductSuggestions Line 24: <%if (Model.ProductSuggestions != null) { %> Line 25: <%if (Model.ProductSuggestions.Any()) { Object reference not set to an instance of an object. Description: An unhandled exc...

How to Cache a large amount of data from database for ASP.NET Mvc

My website uses linq-to-sql to load about 50k rows of data from a database. This data is static and never changes. It works similar to a spam filter and all 50k rows of patterns need to be loaded. What's the best way to program this? for optimal performance? ...