linq-to-sql

legacy database - updating columns

Hi, I have a database in which tables have 4 common columns - Createdby,createdon,modifiedby,modifiedon. Now, the purpose of these columns is track who modified the record.Is there an alternative to this design? Also, how to update these columns - Should I use triggers? But, for "by" columns I need the userid.(we are using linq-to-sql) ...

How to filter Observable Collection Class Collection....

Hi, All I have implemented Linq-To-Sql.. Add necessary table in it... after that linq class will automatically set property for field.. I implemented one class using observable collection class.. and pass datacontextclass object in its constructor... so after getting all data how to filter it ? public class BindBookIssueDetails : O...

Create a table in an existing DB with LINQ to SQL

I have a SQL Express 2008 DB that has gone live. I'd like to create a new table in that database without deleting all the existing data in the live DB. I created an entity class for the new table and a separate data-context. What is the best way for me to add the new table using LINQ to SQL Thanks... ...

Get Distinct Value from Observable Collection Class

Hi I am using Linq-To-SQL. I have made one class by inheriting ObservableCollection This class has one constructor with Datacontext as parameter. I have calling this construtor from my program and assigning it to the control's ItemSource property. But I can't get distinct value in it.. public class BindBookIssueDetails : Observab...

Is there a downside by chosing ntext as datatype for all text columns?

Possible Duplicate: Are there any disadvantages to always using nvarchar(MAX)? Is there a general downside by chosing 'ntext' as column type instead of a type that contains chars but with a limited max size like 'char' or 'varchar'? I'm not sure whether a limited column size is applyable to all my colums. Therefore I would us...

Using LINQ to update a product list with rank

I have a list of products: IQueryable<Product> list = _ProductRepository.GetAll(); The column Product.Clicks corresponds to the number of times the product has been viewed. I want to update this list of products and update the column Product.Rank using a ranking such as this: SELECT ProductId, Name, RANK() OVER (ORDER BY...

Need advice on complex insert scenario using LinqToSql with repository pattern

I have a User table and a ClubMember table in my database. There is a one-to-one mapping between users and club members, so every time I insert a ClubMember, I need to insert a User first. This is implemented with a foreign key on ClubMember (UserId REFERENCES User (Id)). Over in my ASP.NET MVC app, I'm using LinqToSql and the Repositor...

Can't store a korean string in database using LINQ

I'm using this code to store korean string in my database: Dim username As String = Request.QueryString.Get("Some Korean String") Using dg As New DataContext() Dim newfriend As New FriendsTable With {.AskingUser = User.Identity.Name, .BeingAskedUser = username, .Pending = True} dg.FriendsTables.InsertOnSubmit(newfriend) dg.SubmitChanges...

Short-circuit evaluation and LINQ-to-NHibernate

It seems that LINQ-to-NHibernate and LINQ-to-SQL does not support short-circuit evaluation in where clause of query. Am I right? Is there any workaround? May it be added to next versions of LINQ-to-NHibernate and LINQ-to-SQL? for more information plz see followings: http://stackoverflow.com/questions/772261/the-or-operator-in-linq-w...

'LINQ query plan' horribly inefficient but 'Query Analyser query plan' is perfect for same SQL!

I have a LINQ to SQL query that generates the following SQL : exec sp_executesql N'SELECT COUNT(*) AS [value] FROM [dbo].[SessionVisit] AS [t0] WHERE ([t0].[VisitedStore] = @p0) AND (NOT ([t0].[Bot] = 1)) AND ([t0].[SessionDate] > @p1)',N'@p0 int,@p1 datetime', @p0=1,@p1='2010-02-15 01:24:00' (This is the actual SQL taken from SQL Pr...

Linq to SQL: Populating an extended generated class in a Linq Query

Ok so, I have a class that's generated when I created the Linq to SQL connection. It basically looks like this: public partial class Product { public string Name { get; set; } public string Description { get; set; } } I extended it by adding another property, like this: public partial class Produc...

Partitioning of the database in SQL Server 2005

My project modules are organized in such a way that I have to maintain following Database structure. I've 5 schemas, each containing 20 to 50 tables. Each schema is associated with one module of the project. All the tables that are used within more than one modules are kept in "COMMON" schema. Each module takes 2 to 5 months to finish....

Why removed List<Entity> not reflectiong when SubmitChanges() called?

I have this e.g. code: var list = (from item in db.Table select item).ToList(); [do processing where I modify,add,remove items to the list with a DX GridControl] [Ensure inserted items] [I can see that item(s) are not in the list] db.SubmitChanges(); Changes not reflecting the DataBase for removed items. What is wrong? ...

Requirements for using an SQL database in a program.

I have been experimenting with writing applications that use a local SQL Database to store data. I am using Visual Studio to create Windows Forms applications and then connecting them to a database and using LINQ to SQL to pass data to and from the DB. My question is, when I deploy this program on a target machine, what requirements must...

Count number of times a record is refrenced in another table using LINQ-To-SQL

I have a SQL Server table named DeficiencyTag and its PK is an integer named DeficiencyTagID. It will have a couple hundred records. There's another table named Deficiency that references a particular DeficiencyTagID. There will be millions of these eventually. What I need to do is make a list of the top 10 DeficiencyTag records based ...

Lin2Sql No supported translation to sql exception.

Hi, I have the following code. var query = ( from i in _service.GetTimesheetWeeklys() from s in _service.GetStatuses() where i.ProjectID == _projectid && s.ID == i.Status select new { InvoiceID = i.ID, Do...

How to architect my service/repository code with Linq2Sql!

Hi, I have a problem in architecting my application. I have the following structure with only important aspects shown. namespace Domain { public class Invoice { //properties } public class InvoiceRepository { public Linq2SqlContext context = new Linq2SqlContext(); public IQueryable<Invoice> GetInvoices() { ...

Help converting an sql query into LINQ

Hey, I'm trying to convert some SQL I've patched together into a LINQ query. The context is a simple quiz app. A quiz has quizrounds, contestants are one to one attached to quizrounds, rounds have registered answers. The case is that I have a one to many relationship between tables 'quizround' and 'answer'. I want to do a ranking of a...

Linq macro substitution

Hi I can build up a sql string by concatenating a string i.e. String fieldname =”Company”; String tableName= “Address”; “select “+fieldname+” from “+tableName How can I do this with Linq? TIA Stuart ...

Disable triggers in LINQ to SQL

We have created a table with a trigger that updates a ModifiedDate field in it each time there is an UPDATE/INSERT. For a particular transaction in our app, though, we would like to temporally disable this trigger. Would it be possible to do this directly from LINQ? (Directly, not calling a stored procedure) ...