linq-to-sql

Is it possible to create a natural many to many relation in LinqToSql?

I have a content table and tags table I'd like to model a many to many relation between them. Can I hide the many to many table in Linq to SQL? So that my content will receive a field with a set of tags? Or should I switch to NHibernate? ...

LINQ TO SQL am I missing something obvious here?

I have this method, that will be called against from a WCF Client, but for my testing, I'm uisng a local "add project reference." I'm getting the error that I cannot call the DataContext after it's disposed. public IEnumerable<Server> GetServers() { // initialze to null ServersDataContext sdc = null; try...

repository pattern with a legacy database and Linq to SQL

I'm building an application on top of a legacy database (which I cannot change). I'm using Linq to SQL for the data access, which means I have a (Linq to SQL) class for each table. My domain model does not match with the database. For example, there are two tables named Users and Employees, and therefore I have two Linq to SQL classes n...

Linq2SQL Generic Stored Procedures?

Is there a way to do with stored procedures what you can do with GetTable? For example, you can do: var results = GetTable<Client>().Where() // etc Can we do that with Sprocs? I'm trying to avoid the terrible result of using code generation to have strongly typed sproc names. This doesn't adhere very well to persistence patterns no...

Deleting hierarichal objects from databae LINQtoSQl

Hi, I have this hierarchy.I have a customer.A customer can have multiple manufacturing sites.And, each site can have many products.My requirement is, when I delete customer, then data related to site and products should also be deleted. How to achieve this in linq-to-sql thanks ...

Return object with related child objects from database

i have two tables Orders and OrderItems in my sql database, also there is an association between them, [Order.Id]~[OrderItem.OrderId].... the generated class Order By linq2sql has a property "OrderItems" type of "EntitySet" , but when it returns the Order from database, OrderItems Property is empty, how can i get order with related order...

Are Linq to sql objects serializable for session state?

Without going into whether this is a good or bad idea: Is it possible to store a LINQ-to-SQL domain object in the ASP.NET Session, when the session is out-of-process? [EDIT] I'm currently getting the following error and asked this question because I suspect the LINQ-to-SQL objects: Unable to serialize the session state. In 'StateServe...

(Asp.net) I can't Insert a new row using Linq to Sql

So I'm trying to do a simple insert using Linq but i'm running into trouble. code: TestDatacontext db = new TestDatacontext (); Comment com = new Comment(); com.UserID = userId; com.TaskID = taskId; com.Description = Server.HtmlEncode(txtComments.Text); com.DateCreated = DateTime.Now; N...

How do I do this in LINQ

Ok I now have this public IEnumerable<roomvu_User> GetLocationUsers( long LocationID, DateTime StartDate, DateTime EndDate, int StartRows, int MaximumRows) { using ( DataClasses_RoomViewDataContext context = Context ) { IEnumerable<roomvu_LocationMapping> Mappings = ( from m in context.ro...

Linq Date comparision problem

i have the following code but it does not work to comapre a date converted form string can any body help me on this thanks in advance DateTime dt = DateTime.Now; List<DateTime> dateTimes = new List<DateTime>(); dateTimes.Add(dt); dateTimes.Add(dt); dateTimes.Add(dt); string str = dt.ToStri...

Duplicate entries

Hi there, I have created a universalrepository that takes the type passed to it and when I create data entry method, the entity is created fine, but when I create a linked entity to it, i get the base entity created again. Any ideas why? Details.. I have divided a specification into multiple tables to manage stuff... Now I have got a...

Help with linq join

Hi there, I have the following expression in linq (its a join) and i am selecting into "J" because i need to use J later (currently i just selecting J but once i have this fixed i plan on use J within another subquery after) But it won't let me supply a where using the "V" side hence v.IdOFfice is invalid. I have tried swapping around ...

Entity Framework - Select specific columns and return strongly typed without losing cast

I'm trying to do something similar to this post where I don't pull back all columns from a particular entity, however my framework makes use of inheritence and I lose scope of the entity type after it's been cast to an anonymous type. The structure of my Entity Framework has a base entity called Action. From here I've created two inhe...

How is Linq-to-Sql abused?

I hear a lot of linq-to-sql bashing and how people will unknowingly abuse it. But how is linq-to-sql being abused? Update If someone can give me clear examples of how it's abused that would be very helpful. References to blogs/tutorials would be very helpful as well. Thanks. ...

Using Linq to Sql to find ZipCodes within Radius distance

I have a database table of zipcodes with their Lat/Longs. I'm trying to find some code that shows a query that takes a zipcode and x miles and then return set of results that include all the zipcodes that are within that radius (precision is not very important - as long as it's close). Can this be done with a Linq to SQL query so I don...

LINQ to SQL for Large Projects

I'm beginning to wonder if L2S is suitable for large projects. By a large project I mean a database containing many tables spread across many schemas. We would like our entities contained in namespaces that match our database schema names. We have database parent / child relationships that span across schemas. This means our parent / chi...

AsQueriable() or Expression<T>.Compile()?

Edit2: After finally being able to profile the two against each other, it appears that in my situation .AsQueryable() is slightly faster than Expression.Compile(). Original question: I have implemented a cache of some database tables (as List<T>) that I need to query with the same Expression<Func<T, bool>> as I would use when querying a...

Linq to SQL case sensitivity causing problems

I've seen this question, but that's asking for case-insensitive comparisons when the database is case-sensitive. I'm having a problem with the exact opposite. I'm using SQL Server 2005, my database collation is set to Latin1_General_CI_AS. I've got a table, "User", like this: CREATE TABLE [dbo].[User] ( [Id] [int] IDENTITY(1,1) NOT N...

Linq to SQL: Queries don't look at pending changes

Follow up to this question. I have the following code: string[] names = new[] { "Bob", "bob", "BoB" }; using (MyDataContext dataContext = new MyDataContext()) { foreach (var name in names) { string s = name; if (dataContext.Users.SingleOrDefault(u => u.Name.ToUpper() == s.ToUpper()) == null) dataConte...

Identify source of linq to sql query

We are starting to have numerous linq to sql queries in our code. We have started to pay more attention to performance and are starting to see queries that we think are coming from linq. They have the t1, t2...tN values, so we are sure they are linq generated. However, we are having difficulty determining the location in code that is the...