linq-to-sql

Asp.net(C#),How to retrive data from database?

In asp.net(c#),I use Linqtosql.. how to retrieve data from database(table) and display in textbox...? ...

How to databind a textbox to a DB field using LINQ to SQL, the right way?

Currently I'm writing an ASP.net webforms app, which works with a table containing 15 fields. I'm using LINQ to SQL which is very good to use and everything, but when i need to bind the fields with the text boxes (15 of em), whats the best way currently I'm doing this ... ... var stud = db.Students.SingleOrdefault(d => d.ApplicationNo =...

Will .net 4.0 runtime work with SQL Server 2000?

According to this article, Visual Studio 2010 no longer supports SQL Server 2000. However, it's a bit less clear on whether the runtime (and things like ASP.net 4.0, Linq2SQL and EF) will work with it. It seems that only the design-time features require SQL Server 2005 or greater according to that article. I have a project that requir...

want a Query to make order by variable in Linq query

How to make order by Column variable because I have a dropdown on page and I want to show grid according to sord order selected in this Dropdown e.g Price, Code, rating, description etc etc. and I donot want to write a separate query for each column. from lm in lDc.tbl_Products where lm.TypeRef == pTypeId orderby lm.Code ascending se...

How to create category and list in one query with Linq

I want to create something like this using a DataList and Flow markup: |-----------------------| | Title | |-----------------------| | [x] Title | | [x] Title | | ... | ------------------------- I have a table (modeled in Linq2Sql) Foo that has these fields int id; int? parent...

How to convet mutliple SQL left joins to Linq-To-SQL

I have a user table, a user_items table, a user_to_group table and a group table. How would I convert the following SQL query to the correct Linq-to-sql query? select user.username, user.email, user_items.item_number, item_types.desc, [group].name from user left join user_items on user.user_id = user_items.user_id left join item_types ...

Edit Post action - why does respository.save() save the data?

Hi I am a tad befuddled. I can't reason why the following works: AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, FormCollection formValues) { Dinner dinner = dinnerRepository.GetDinner(id); UpdateModel(dinner); dinnerRepository.Save(); return RedirectToAction("Details", new { id = dinn...

Migration from linq2sql to EF4.0

In linq2sql I had this code to implement base class for repository public abstract class Repository<T> : IRepository<T> where T : class { protected DataContext context; protected Table<T> table; public Repository (DataContext context) { this.context = context; table = context....

Telerik OpenAccess ORM - Is anyone using it?

I'm working on a new project right now and am thinking of using an ORM beyond that of Linq to SQL. I've currently got Linq to SQL wired up into a repository, but I'm not loving the way my Repo has to match my DB structure. (Example: I have a join between Users and OpenID's, and I need a 2 classes ( one for each table) and a class for t...

I'm a Linq-to-SQL rookie, but I'm looking into Entity Framework. Is it much harder to use?

For example, one of the joys I've learned from L2S is that when creating the .dbml file, it automagically lets me create object of the Table with fields of the table columns. I do absolutely nothing and I can query things using a very natural approach using Linq and lambda expressions. I've also been told that L2S doesn't work with many...

How to set DateTime format in lambda expression?

I am using linq-to-sql joins and group by features to fetch the data I need. I got everything worked but the dateTime format. Here is my code from emp in dc.Employees join lv in (from l in dc.Leaves group l by l.RequestID into le select new { ...

How does the DataContext handle concurrency?

I wonder how the DataContext handles concurrency violation. For example - Two users are fetching some data from the database, then some of them change some row and commit changes, then other user trying commit their changes so a ChangeConflictException should occur, but how does the DataContext know that the data has changed? Fetch...

LINQ Average TimeSpan?

Hello all, I have a database table that contains entries for start time and end time of an event. I would like to take those entries and find the average length of an event. The subtraction is no problem. However, when I try to get the average value, the compiler complains. Here is my current LINQ query: public TimeSpan? getAverageTim...

[SQL/Linq to SQL] How do I group/aggregate but return fields other than the aggregation field?

I have two tables, Tasks and TaskMilestones. I want a query to return the most recent past milestone and the nearest future TaskMilestone for each Task. I'm working with C#/LINQ-to-SQL. How do I go about this? Task columns: Id, TaskName TaskMilestones columns: Id, TaskId, MilestoneName, MilestoneDate I want a return table with rows...

Appropriate spot for security evaluations - business logic or data access

Pardon the length here...hopefully I didn't go overboard... I'm in the process of working on my first production MVC application and I'm trying to stick to DDD principles in the process. I've run into some questions related to how to deal with the security requirements of the application and thought I'd see if the SO community could of...

What is the best-practice way to use Linq-to-SQL in a C# application? [Design-pattern]

OK, I'm always trying to improve the way I code because it's my passion. I have a .dbml file (linq-to-sql) and I use it to access my MS SQL database. Imagine, if you will, that you have a Person table in your database and you want to provide a way to delete,add,modify a Person record. The way I'm handling things currently is creating ...

.Net bindingcontext update method

Hello, I'm using databinding (through LINQ to SQL) in a C# form and I need to know how to update the BindingContext when a new item is added to my Table. More specifically, I have form that displays the properties of a project in various fields. The user can traverse to different projects through the project name combo box. At the ...

Linq-to-sql datacontext class design question?

I'm using linq-to-sql in a web scenario only. I know it is recommended to always wrap the datacontext in a using but in a web scenario only, the kind of scenario I'm designing for, this is really not necessary because each page will spawn and die in very short time. Given that background, I've looked at extended some of my linq-to-sql c...

Designing an append-only data access layer with LINQ to SQL

I have an application in mind which dicates database tables be append-only; that is, I can only insert data into the database but never update or delete it. I would like to use LINQ to SQL to build this. Since tables are append-only but I still need to be able to "delete" data, my thought is that each table Foo needs to have a correspo...

LINQ to SQL: set PK using DataContext "Insert" partial method

I'm trying to achieve something similar to what's described in this old SO post, which never got a proper answer. I'm trying to find a way to delegate setting the primary key of newly inserted objects to the DataContext InsertX() partial methods when SubmitChanges() is called. Essentially, this makes primary key generation lazy, and bett...