linq-to-sql

Design pattern for data entry forms with LINQ2SQL

I am about to start a new winforms data entry application, it already has the database designed which I am comfortable with. I was going to use LINQ2SQL to access the tables to keep things type safe but am now wondering about design patterns, something I am just getting into. Since LINQ is giving me objects to use should I still create...

Using LINQ GetChangeSet() to show user what happened

Say I have a L2S Update and I would like to display what changed to the user. Where does GetChangeSet() get populated? Immediately after I assign values or after context.SubmitChanges()? If the second; I could, theoretically, change the return type to IList and then return return context.GetChangeSet().Updates;? ...

How can I create a generic UniqueValidationAttribute in C# and DataAnnotation?

I'm trying to create a UniqueAttribute using the System.ComponentModel.DataAnnotations.ValidationAttribute I want this to be generic as in I could pass the Linq DataContext, the table name, the field and validate if the incoming value is unique or not. Here is a non-compilable code fragment that I'm stuck at right now: using System; u...

LINQ to SQL: Get records from two DB's that are on different servers.

I need to fetch records from tables, that are in two diff. databases in two different SQL Servers. For Instance. Sales DB on server1 and Purchase DB on server2. Both Sales and Purchase DB's have some set of tables say table1 in Sales DB and table2 in Purchase DB. Now, I need to get records from table1 and table2 that are having some co...

Translate SQL to LINQ query - group/join/filter

I have the following query: SELECT S.[FlowOrder], S.[DESCRIPTION], COUNT(I.ID) FROM WorkFlowStatus AS S INNER JOIN Item AS I ON S.ID = I.StatusID WHERE I.Installation = '1' GROUP BY S.[Description], S.[FlowOrder] ORDER BY S.[FlowOrder] Which gives me the count of an item, grouped by a foreign key to workflow, outputting the descri...

Method of saving the row creation time which can be generated by SQLMetal

I'd like to save the creation time of a row, so I have created a datetime column and set it's Default Value to be Getdate(). But when I generate the dbml file from SQLMetal and re-create the database from it, the function is missing. I've added the /functions parameter to the command line when running SQLMetal but this didn't fix the pr...

dotConnect LINQ to MySQL Issue

I am using dotConnect LINQ to MySQL and i have the following error. what would be the cause for this issue annot convert parameter value of type 'System.String' to MySQL type 'MySqlType.TimeStamp'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informa...

Linq To Sql Concat() dropping fields in created TSQL

This is strange. I am moving a stored proc to a service. The TSQL unions multiple selects. To replicate this I created multiple queries resulting in a common new concrete type. Then I issue a return result.ToString(); and the resulting SQL selects have varying numbers of columns specified thus causing an MSSQL Msg 205... using (var db...

LINQ Query returns nothing.

Why is this query returns 0 lines? There is a record matching the arguments. SomeDataContext db = new SomeDataContext(ConnString); return db.Deafkaw.Where(p => (p.SomeDate1 >= aDate && p.SomeDate1 <= DateTime.Now) && (p.Year == aYear && p.IsSomething == false) ).ToList(); Am i missing something? On the Tabl...

How do I setup Linq to SQL and WCF

So I'm venturing out into the world of Linq and WCF web services and I can't seem to make the magic happen. I have a VERY basic WCF web service going and I can get my old SqlConnection calls to work and return a DataSet. But I can't/don't know how to get the Linq to SQL queries to work. I'm guessing it might be a permissions problem s...

Taking a snapshot (cloning) of a project using Linq 2 Sql

I have a Project entity with several child tables, eg ProjectAwards ProjectTeamMember I would like to copy the data from Project (and child tables) into a new Project record and update the Project status. eg var projectEntity = getProjectEntity(projectId); draftProjectEntity = projectEntity draftProjectEntity.Status = NewStatus cont...

LinqToSql Select to a class then do more queries

I have a LINQ query running with multiple joins and I want to pass it around as an IQueryable<T> and apply additional filters in other methods. The problem is that I can't work out how to pass around a var data type and keep it strongly typed, and if I try to put it in my own class (EG: .Select((a,b) => new MyClass(a,b))) I get errors w...

how to retrieve the (OUTPUT) value of a SPROC using linq2Sql

Hello, Let's say I've one model HierarchyData and 2 tables (Organizations and Hierarchies). The Organization table contains info on individual Organization while the Hierarchies table contains only int values (identity of each organization) that represents how thos organizations depend on each other. (i)I need to create a group of org...

Is there an automatic way to generate a rollback script when inserting data with LINQ2SQL?

Let's assume we have a bunch of LINQ2SQL InsertOnSubmit statements against a given DataContext. If the SubmitChanges call is successful, is there any way to automatically generate a list of SQL commands (or even LINQ2SQL statements) that could undo everything that was submitted at a later time? It's like executing a rollback even though ...

Entity Framework VS LINQ to SQL VS ADO.NET with stored procedures?

How would you rate each of them in terms of: Performance Speed of development Neat, intuitive, maintainable code Flexibility Overall I like my SQL and so have always been a die-hard fan of ADO.NET and stored procedures but I recently had a play with Linq to SQL and was blown away by how quickly I was writing out my DataAccess layer a...

Linq To Sql why am I getting duplicate records?

In the following code GetUserAction does return an instance of action but when the user instance is submitted to the database it creates an additional action row in the database instead of creating a relationship with the existing row that is returned? Why? using (UserRepository repository = new UserRepository()) { var user = new us...

linq to sql with nservicebus table lock issue

I am building a system using NServiceBus and my DataLayer is using Linq 2 SQL. The system is made up of 2 services. Service1 receives messages from NSB. It will query Table1 in my database and inserts a record into Table1 If a certain condition is met a new NSB message is sent to the 2nd service Service2 will update records also in Ta...

How to pull a RANDOM and UNIQUE record from SQL via LINQ.

Okay, I found lots of posts on SO about how to pull a RANDOM item from the database when using LINQ. There seems to be a couple of differnet ways to handle this. What I need to do though is pull a RANDOM item from the database that the user has not seen before. The data I am pulling from the database is very small. Is there any way I ca...

Dump Linq-To-Sql now that Entity Framework 4.0 has been released?

The relative simplicity of Linq-To-Sql as well as all the criticism leveled at version 1 of Entity Framework (especially, the vote of no confidence) convinced me to go with Linq-To-Sql "for the time being". Now that EF 4.0 is out, I wonder if it's time to start migrating over to it. Questions: What are the pros and cons of EF 4.0 rela...

Is saving to database just to get an ID a bad hack?

I hope the title is not too confusing. I am trying to make folders with linq-to-sql objects' IDs. Actually I have to create folders before I should save them. I will use them to keep user uploaded files. As you can see I have to create the folder with the FileID before I can save it there. So I just save a record which will be edited or ...