linq-to-sql

linq to sql insert query not working from unit test project

I'm having a strange behavior in Linq to Sql... I have a simple parent | child (one to many) object model. In my app, I create the parent object and populate the children all in memory, and then call my repository's add method to insert both the parent with its children. Now from my application (winform), all works correctly as expect...

Conversion C# to VB.net Linq to Sql

Need vb.net conversion of the below: orginal question at LINQ To SQL "Group By" from S in SERVER join H in SERVERHDD on S.Server_ID equals H.Server_ID join FILTER in (from s in SERVERHDD group s by new {s.Server_ID, s.Letter} into groupedServerHDD select new { SERVERHDD_ID = gr...

Does LINQ to SQL use the ActiveRecord Pattern?

I've just been researching the ActiveRecord pattern, and based on this (http://en.wikipedia.org/wiki/Active_record_pattern), it seems Linq 2 Sql more or less implements this, am I wrong? or what would need to be changed for it to conform to the ActiveRecord pattern? ...

Linq2Sql Pivot

Hi all I have the following query var q = from item in new DataAccess.IncidentRepository().GetItems() group item by new { item.Supplier, item.SupplierPlant } into item select new { ...

Cascading Delete / Update in LINQ-to-SQL class

Hi, I am not deleting records permanently (just maintaining flag) but I'd like to know how cascading delete / update works in LINQ-to-SQL class. EDIT If I have similar situation e.g. maintaining flag for Delete option. How do you achieve Cascading Delete for your database? ...

Can LINQ to SQL and traditional Stored Procedures co-exist?

First, to be clear, I am not talking about LINQ to SPRocs. I have an existing DAL that uses over a 100 stored procedures. This was created when this program was a web app. Now it is a winform app in a sometimes connected environment that uses a local db. I have left the existing DAL in place in the interest of time but am now find...

Linq with hierarchy in the data base. How do I pass on the keys?

Hi all, Here is the scene. Agents -> Organization -> Schools Agents -> Persons -> Educators So each of the 5 tables exist in the data base. The AgentId (GUID -> uniqueidentifier) is generated in the Agents table and I need it to be passed on to Organization -> Schools or Persons -> Educators. But Linq to SQL does not reconize that, an...

How can I get an OR in my Where clause?

I'm building an ad-hoc query to send to SQL doing the following: var data = from d in db.xxxx select d; foreach (pattern in user_stuff) data = data.Where(d=>SqlMethods.Like(d.item,pattern)==true); The problem is that the WHERE clauses get AND'ed together. I need OR's. Any idea how to get an OR? ...

How can I keep up with new technologies?

Duplicate: Learning implementing design patterns for newbies I have been a developer for years and have my way of developing and have always kept up with the latest techologies. I want to start using a design pattern in the hope it will improve my development speed but I need to find one to apply and I need to find a full open so...

LINQ to SQL external mapping

I don't know how to set up external mapping file for LINQ to SQL. I've read Ivan Latunov's blog post about it and it woke up my interest in it. The problem is that I don't understand how things should go. The main question is: what is the howto if I want only to modify xml mapping file? Do I first create .dbml file and then supply Mappin...

How can I use LINQ to return a list of Countries but place a particular country aribitrarly at the top?

I have a table with a list of countries in it that I'm using to populate a dropdown. How can I construct a LINQ query so it will return the list of countries from that table in alphabetical order, with the exception of placing USA at the top? So, if the table contained: Sweden USA Mexico Denmark It would return: USA Denmark Mexico S...

Ok dumb question time. Linq to SQL. Join.

I have two tables: Clients, and a join table that has user id, a foreign key to clients, and some other stuff. I want to do this SQL select TblClient.* from TblClient inner join tblUserClientProjJoin as b on TblClient.Client_ID = b.Client_FK where b.User_fk = 2 So getting a list of 'clients' that a specific user has access to. I w...

How to run stored procedure in ADO.NET Entity Framework?

I added this code below: public partial class Form1 : Form { TestAdonetEntity2Entities entityContext; public Form1() { InitializeComponent(); entityContext = new TestAdonetEntity2Entities(); } private void Form1_Load(object sender, EventArgs e) { dataGridView1.DataSource = entityContext.S...

How do I run a stored procedure in ADO.NET Entity Framework?

How to use stored procedure in ADO.NET Entity Framework? My Table : MyCustomer Columns: CustomerID PK int Name nvarchar(50) SurName nvarchar(50) My stored procedure ALTER procedure [dbo].[proc_MyCustomerAdd] (@Name nvarchar(50), @SurName nvarchar(50) ) as begin insert into dbo.MyCustomer([Name], Sur...

linq to sql , model first development ?

Hi, Is is it possible to use l2s in model first approach? Here's the think i want to achieve: I want to write my app in TDD manner, so I want to write some domain specific objects first and then base on that generate database model. One solution is to l2s as DAL but and map linq generated entities to my custom domain objects(I Rob C. in...

LINQ Select() function throws out loaded values (loadoptions)

Hi All, I have a model where a Product can have multiple PriceDrops. I'm trying to generate a list of products with the most recent price drops. Getting the most recent price drops with the products loaded is easy enough, and I thought it would be the best way to start: dlo.LoadWith<PriceDrop>(pd => pd.Product); db.LoadOptions = dlo;...

Linq2Sql: Can I create entities with foreign key relationships without a primary key in both tables?

I have 2 tables in my database that I'm trying to create Linq2Sql entities for. There's more to them than this, but this is essentially what they come down to: Rooms UserActivity -------- -------- RoomID ActivityID RoomID (foreign key on Rooms.RoomID) The UserActivity table is essentially just a...

C# Linq to SQL: How to express "CONVERT([...] AS INT)"?

In MSSQL you can convert a string into an integer like this: CONVERT(INT, table.column) Is there any C# expression that Linq to SQL would translate to this? In C# you can normally do the same by using int.Parse(), but unfortunately, trying to use int.Parse() in a Linq query results in an error: Method 'Int32 Parse(System.String)'...

Why does the following SQL Server insert deadlock when run within a transaction?

I'm currently inserting a record into a SQL Server Table and then selecting the auto-increment ID as follows: (@p0 int,@p1 nvarchar(8))INSERT INTO [dbo].[Tag]([Some_Int], [Tag]) VALUES (@p0, @p1) SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value] (This was generated using Linq-to-SQL). For some reason when I run this code inside a trans...

Counting the result LINQ

I am using the following var validLogin = from P in this.DataContext.Persons where P.UserName.Equals(login) && P.Password.Equals(password) select new { P.FirstName, P.LastName, P.EmailAddress }; In this now i want to know, is t...