linq-to-sql

How do I change this query to linq to sql?

Query: select emp.empname as Name, dep.depname as Department from Employee as emp inner join Department as dep on emp.depid=dep.depid where emp.id='2' How can I change this to linq to sql? ...

Update observable collection by requerying or adding to collection?

I have a observable collection exposed as a property within a view model. The observable collection is loaded with objects from a data access layer (linq2sql). When a new item is added to the database through another view model what is the best way to update the observable collection? Should I repopulate the observable collection with a...

Showing multiple models in a single ListView

I've three models (Contacts, Notes, Reminders). I want to search all these and produce the filtered result in a single listview and depending upon the selection I've to display the corresponding view(UserControl) to its right. I want the right way of implementing the design or atleast alternatives to this method that I've tried. Now I'...

Linq-To-SQL Vs T4 Template.

I am using Linq-to-SQL for my projects but i heard about the T4 Template Code generator? Whether T4 Template is better then Linq-To-SQL Data Context? ...

why datetime.now not work when I didn't use tolist?

When I use datacontext.News .Where(p => p.status == true) .Where(p => p.date <= DateTime.Now) .ToList(); the system will return no results; When I use datacontext.News .Where(p => p.status == true) .ToList() .Where(p => p.date <= DateTime.Now) .ToList(); system will return expected results. Can anyone t...

How do I check if a Linq to SQL entity has grandchildren?

How can I find out if a Linq to SQL entity has grandchildren or not? Pseudo-code below: Return From p In dc.Processes Where p.Signers.Count > 0 and p.Signers.Signatures.Count > 0 Obviously I can't run the code above but I need to make sure that all the returning Processes have at least one Signer and that all of those Signers have at...

LINQ 2 SQL:Left outer join for my SQL statement

Can any one tell me the LINQ 2 SQL version (in vb.net) of the below Left outer join query.I am trying to get all Employees with name "Shyju" and their address line 1 if it exist in the address table SELECT E.EMPLOYEE_NAME, E.AGE,A.ADRESS_LINE1 FROM EMPLOYEE_MASTER E LEFT OUTER JOIN ADDRESS_MASTE...

How can I check if a user has written his username and password correctly?

I'm using a Linq-to-SQL class called Scans.dbml. In that class I've dragged a table called Users (username, password, role) onto the graphic area and now I can access User object via a UserRepository class: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Scanner.Classes { public clas...

How can I translate this SQL statement to a Linq-to-SQL approach?

For example, imagine that I want to see if a user exists in my database: Select * from Users where inputID = Users.ID Then if that result brought > 0 items, then the user exists, correct? How can I do something like this using a pure Linq-to-SQL class? ...

Using a Linq-To-SQL class automagically generates the connection string for me; is there a way to manually set it?

I'm just beginning to use Linq-to-SQL and it's just wonderful to use. The problem is, this software is going to be run on a lot of machines and each machine will have a unique connection string. Is there a way for me to manually set the connection the Linq-to-SQL (.dbml) uses? The way I'm doing things now is creating the .dbml file, an...

Does linq to sql make stored procedures in ms sql 2005?

Hi I am looking through my stored procedures on my server and I got alot of them. The thing is I only made like 10 of the 100 there. These stored procedures are not system ones(that has its own folder). They seem to be stored procedures for every table I have. Example of one USE [DB] GO /****** Object: StoredProcedure [dbo].[usp_S...

Generated sql from LINQ to SQL

Following code ProductPricesDataContext db = new ProductPricesDataContext(); var products = from p in db.Products where p.ProductFields.Count > 3 select new { ProductIDD = p.ProductId, ProductName = p.ProductName.Contains("hotel"), ...

Change Connection string in LINQ-SQL.

Hi, I have developed a windows form application using VB.Net with data access layer using LINQ-SQL. I want to allow the database to be configured from the application. I have created a form for input and save the input details in an XML file. I need to know how to configure the LINQ to start using the new configured database on startu...

linq to sql dynamic data modify object before insert and update

I'm using Dynamic Data and LINQ to SQL for some admin pages on a .NET 3.5 web app. All my admin tables have a CreatedBy, CreatedDate, UpdatedBy, and UpdatedDate. I'm looking for a way to inject the setting of these properties before the objects are inserted and updated. I've seen an object_inserting hook if you have a linq to sql data...

Linq to SQL query error

public class Service1 : IService1 { [OperationContract] public List<decmal> GetEnterCounts(DateTime StartTime, DateTime EndTime) { var db = new FACT_ENTER_EXIT(); return (from e in **db.ENTER_CNT** where StartTime < db.DATE_ID && db.DATE_ID > EndTime select e).ToList(); } } Ok, so I have this database FA...

How to store a list in a column of a database table.

Howdy! So, per Mehrdad's answer to a related question, I get it that a "proper" database table column doesn't store a list. Rather, you should create another table that effectively holds the elements of said list and then link to it directly or through a junction table. However, the type of list I want to create will be composed of un...

Will this safely delete my record?

I hate these three tables that. Two tables have a many to many relationship and as such it generates a third table. I'm using Linq-to-SQL and in the .dbml file I've dragged all the folder there to the graphic surface. Here is the method I'm using to delete an Area safely. Remember that documents are associated to an Area, so I can't ...

The type arguments for method cannot be inferred from the usage. Try specifying the type arguments ex - error. Any guidance?

/// <summary> /// Find all of the Areas that are Parents without children Areas. /// </summary> /// <returns>IQueryable object full of Areas.</returns> public IQueryable FindParentAreas() { return db.Areas.SelectMany(x => x.ParentAreaID == null); } I want to return a collection of Area objects that a...

Visual Studio project template mystery: Why is Context.Designer.vb file excluded?

My source project includes a LINQ to SQL DBML file called Context.dbml. This auto-generates a file called Context.designer.vb, which is included in the source project. I've created a Visual Studio template from this project. But when I go to create a new project using this template, Context.designer.vb is not included, so the new pro...

too many fields to specify in result set of join

hi, So similar questions have been asked with not much of an answer.... I have a Stats Table related to a Branch table. The Stats records contain pc stats of a particular bank branch. Branch +Code +Name +Area ... Stats +BranchCode +IP +UpSpeed +DownSpeed ... Here is my linq query... var stats = from st in store.Stats ...