linq-to-sql

C# 3.0 - How can I order a list by week name starting on monday?

Hi! I have a list of events and each of them has a weekday registered. And now I'm trying to show all of these events, but ordered by the weekday name (monday, tuesday, wednesday...). How can I do this? I'm using LinqToSQL and Lambda Expressions. Thanks!! ...

LINQ - Compiled Queries in VB.net

Anyone have experience with compiled query syntax for VB? I'm used them a few times in C#, but can't seem to make the translation. My code is below: #Region "Locals" 'Data context objects ' Private _dbOrderInfo As New OrderInfoDataContext #End Region #Region "Delegates" Public Shared ReadOnly Func(_dbOrderInfo, Boolean, IQu...

Can I access the list of InsertOnSubmit'd records from a linq-to-sql DataContext?

I have some code where I am using a Linq-To-SQL DataContext to add and modify records in a table. I've run into a situation where I add a few records via InsertOnSubmit, and then I want to modify a record.. but this record may already be in the table, or it may be one of the ones I am inserting. So this: db.MyTable.Single(t => t.Id ==...

Child collection not filtering even though linq to sql join exists

I have a LINQ query: var result = from mt in MessageTypes join mtfmt in MessageTypeField_MessageTypes on new { MessageTypeID = mt.ID, MessageTypeFieldID = messageTypeFieldId } equals new { MessageTypeID = mtfmt.MessageTypeID, MessageTypeFieldID = mtfmt.MessageTypeFieldID } where (mt.StatusID == (int)status) sele...

LINQ Code Generation Property Names

Hi, I am using LINQ To SQL to handle data access in a project. For a case where I have multiple foreign keys in a table to the same table (for e.g. CustomerUserId, TechnicianUserId) , it generates the property names like ApplicationUser and ApplicationUser1. Is there a way to tweak the code generator to produce easier to read names. I...

SQL server profiler not showing LINQ To Sql queries

I am trying to view SQL generated by Linq to SQL in the SQL Server Profiler (2005). I can see the sql sent to the server from anything except for linq to sql. I'm betting that I need to change event selections for the trace, but not sure what else to select. I am currently only selecting this: SQL:StmtCompleted - TextData & SPID I do...

LINQ to SQL query against a list of entities

Ingredient class: class Ingredient { public String Name { get; set; } public Double Amount { get; set; } } List of Ingredients: var ingredientsList = new List<Ingredient>(); Database layout of my "Ingredients" table: [Ingredients] ( [IngredientsID] [int] IDENTITY(1,1) NOT NULL, [RecipeID] [int] NOT NULL, [Ingre...

LINQ to SQL: Advanced queries against lists, arrays and lists of objects

Single and multiple lists Consider the following lists: List<Int32> appleIdentities = new List<int>(new[] { 1, 2, 3 }); List<Int32> chocolateIdentities = new List<int>(new[] { 2, 3, 4 }); List<Int32> icecreamIdentities = new List<int>(new[] { 11, 14, 15, 16 }); Using LINQ to SQL; is it possible to wite a statement which translates in...

Best design practices for .NET architecture with LINQ to SQL (DAL necessary? Can we truly use POCOs? Design pattern to adopt?)

I was avoiding writing what may seem like another thread on .net arch/n-tier architecture, but bear with me. I, hopefully like others still am not 100% satisfied or clear on the best approach to take given today's trends and new emerging technologies when it comes to selecting an architecture to use for enterprise applications. I suppo...

Linq to SQL ORM 3-layer question

I am designing this HR System (desktop-based) for a mid-size organization. The thing is I have all the tables designed and was planning on using the O/RM in VS2008 to generate the entity classes (this is the first time I work with OR/M; in fact, this is my first "big" project.) I wanted to make the app with 3 layers (one of the programme...

Entity base class design in C# for repository model

I am trying to become a good programming citizen through learning more about Dependency Injection / IoC and other best-practices methods. For this I have a project where I am trying to make the right choices and design everything in the "proper" way, whatever that might mean. Ninject, Moq and ASP.NET MVC help with testability and getting...

how to combine dropdownlists and null fields in gridview?

i have a GridView with LinqDataSource. im using the following technique to populate a field (Supplier in this case) with dropdownlist, containing values from a different LinqDataSource: however, lets say my Supplier field is allowed to be null. any ideas how to allow entering null value, alongside with the other SupplierDataSource opt...

C# Linq-to-SQL: Refectoring this Generic GetByID method

I wrote the following method: public T GetByID(int id) { var dbcontext = DB; var table = dbcontext.GetTable<T>(); return table.ToList().SingleOrDefault(e => Convert.ToInt16(e.GetType().GetProperties().First().GetValue(e, null)) == id); } Basically it's a method in a Generic class where T is a class in a DataContext. The m...

LINQ - Does .Cast<T>() Select Records?

I've noticed that certain command cause LINQtoSQL to connect to the database and download the records that are part of the query, for example, .ToArray(). Does the command .Cast() cause a query to execute (and how can I tell these things in the future?). For example... IRevision<T> current = context.GetTable(typeof(T)) .Cast<IRevis...

Linq to SQL - many to many mapping

Hello, In my project I have 'Player'(PlayerID and data) table, 'Games' table (GameID, Name) and I made a many to many table 'PlayerGames' (PlayerID, GameID - I created the forign keys relations) PlayerID and GameID are primary keys in their tables and the tuple (PlayerID,GameID) are primary key in 'PlayerGames' Table I tried to map th...

LINQ to SQL Auto Inserting Row Copy When Updated

Hi, I am using this simple code to try and update a row var MyDB = new SKN2DataContext(); var s_case = MyDB.SupportCases.FirstOrDefault(sc => sc.Id == 3); s_case.OpenDate = DateTime.Now; MyDB.SubmitChanges(); On the last line i am presented with the following exception Value of member 'Id' of an object of ty...

How do I get the next item in a subset of an ordered table using linq?

I have two tables: Topic ( TopicID: int, (primary key) TopicName: varchar ); Example ( ExampleID: int, (primary key) TopicID: int, (foreign key to Topic table) ExampleOrder: int, ExampleName: varchar ); Using Linq, given an ExampleID, I want to get the next example in the same topic (with the same TopicID). Here's how it ...

LinqToSql - Multiple subqueries creates many roundtrips

I've got two tables that look like this: I'm trying to generate query that includes two specific StatisticsNames for each period from ApplianceStatisticsLog. Below is the Linq query I have come up with. It works but generates a single query for the first sub-select, then one additional query for EACH record for the 2nd sub-select. Ouc...

maintain history in a database

I am designing this database that must maintain a history of employee salary and the movements within the organization. Basically, my design has 3 tables (I mean, there more tables but for this question I'll mention 3, so bear with me). Employee table (containing the most current salary, position data, etc), SalaryHistory table (salary, ...

Convert existing LinqToSQL code to be compatible with other databases

I have a working application that communicates with an SQL Server database. This application makes use of LinqToSQL. For a number of reasons, I want to convert this application to using Microsoft Access instead. (It's a small set of data, concurrent usage is possible but rare, I want to deploy on machines that don't have access to SQL ...