linq-to-sql

Insert a null Value into a smalldatetime column in SQL using LINQtoSQL via VB?

I have a smalldatetime column in SQL that can have a null value, but when I try to insert a null value using SqlTypes.SqlDateTime.Null and LINQtoSQL it puts in 1/1/1900 instead of NULL. What is the best method to insert a null, or am I doing it at the moment. If I am using the correct method at the moment, what should be done to prevent...

LINQ to SQL - How to add a where clause to a left join?

This LINQ query expression emits a left join and works: from p in Prices join ip in ItemPrices on new { p.PriceId, ItemId = 7 } equals new { ip.PriceId, ip.ItemId } into priceItemPrice from pip in priceItemPrice.DefaultIfEmpty() select new { pricesPriceId = p.PriceId, z = (int?)pip.PriceId, p.Content, p.Pri...

Linq TO SQL Right Outer Join

Hello all - here is another Linq TO SQL Join question - I am ok with single joins and have used join into group but this one has multiple joins and right outers and I be stumped ... any help would be greatly appreciated Table structure: category has many sections section has zero or many items items has zero or many attribs T-SQL a...

[ASP.NET MVC] (LINQ-To-SQL) Creating classes first, database table second, how to auto-connect the two?

I'm creating a data model first using the LINQ-To-SQL graphical designer by using right-click->Add->Class. My idea is that I'll set up everything first using test repositories, design the entire website, then as a final step, create a database using the LINQ-To-SQL classes as a model for the database tables and relationships. My reasonin...

How linq 2 sql is translated to TSQL

Hi all, It seems Linq2sql doesn't know how to construct the TSQL while you transform linq2sql object into domain object with constructors. Such as: from c in db.Companies select new Company (c.ID, c.Name, c.Location).Where(x => x.Name =="Roy"); But when using settable attributes, it will be OK. from c in db.Companies select new Comp...

List<TEntity>.Cast<BusinessObject>() fails when implicit cast exists

I get an InvalidCastException converting a linq entity list to a businessobject list using the .Cast<> operator. "Unable to cast object of type 'Ticketing.ticket' to type 'Ticketing.ModelTicket'." (namespace name was changed because underscore was causing unneeded formatting) here's my business object class public sealed class ModelT...

Linq To Sql: The member Date has no supported translation to SQL

Consider a class that's used to represent the results of a GroupBy(). The goal of the code is to replace a stored procedure that would have grouped and counted a bunch of rows by the Created datetime field. public class Statistic { public int NumRecords { get; set; } public DateTime Date { get; set; } } Here's the code raisin...

LINQ to SQl, Self Referencing an Extended Class

I have a "Literal" class that defines a text value and an ID. I want to build a static method that is simply "FromValue(string)" within the Literal class (LINQ to SQL), so that it'll return the proper Literal instance from a given value. I'm having some trouble figuring out how to do this, though. I mean, I can call it in code everytime...

Alias properties in LINQ to SQL

I'm using a shim property to make sure that the date is always UTC. This in itself is pretty simple but now I want to query on the data. I don't want to expose the underlying property, instead I want queries to use the shim property. What I'm having trouble with is mapping the shim property. For example: public partial class Activity { ...

LinQ2SQL using Take to pick top n..

Does Take(N) executes after getting full list or the execution stope after picking the needed top n records Thanks.. ...

Unit testing using Moq, Code using Linq to Sql to stored procedure

I am very new to TDD, ASP.NET MVC and LinqToSql. I am trying to write tests for my repository, which gets data from stored procedure using LinqToSql. This is the repository method being tested: public int GetResponseCount(int campaignId) { var results = (new MyDBDataContext()).GetResponseCountById(campaignId); foreach (GetRespo...

Listing expressions for OrderBy

I would like to be able to store a list of expressions to execute with IQueryable.OrderBy at a later time, something like: List<Expression<Func<MyType, object>>> list = new List<Expression<Func<MyType, object>>>(); list.Add(x => x.Date); list.Add(x => x.ID); IOrderedQueryable<MyType> qry = query.OrderBy(list[0]).ThenBy(list[1]); ...

LinQ Query help

Hello, I have added a table(ViolationsDataSourceConfig) to the dbml file. The context name is ViolationsDataContext. I am trying to write a function that should return employee object but it is throwing errors. Below is the code. Is there any easy way for achieving this. I just want the ViolationsDataSourceConfig. Public Shared Func...

Weight auto increment.

Hey there. I'm searching for a way to auto increment a "Weight" field in my database table using linq to sql.For example if in my database I already have 5 rows with the weights 4,2,7,5,2 , on my new insert in the database the weight should automatically set to 8, because 7 is the largest weight in the set of rows and the next largest o...

How should I handle my Entity/Domain Objects using IoC/Dependency Injection?

I'm currently using PLINQO to generate all my Entities from the database. Recently, I've started to use dependency injection using StructureMap, and as part of the learning process of "separating my concerns". I've noticed that all the generated Entity classes contain highly-coupled properties using EntitySet, part of LINQ, which make m...

Linq to SQL insert via stored proc issue

I have a method that inserts a record into SQL Server using Linq to SQL and a stored proc. However if we refresh the page (it automatically runs a Get method), the updated data doesn't get returned from the Linq query (not a stored proc). I'm guessing if I use a stored proc for the Get, this will solve the issue as it seems the context...

data not deleted from DB when removing items in RIA Services

I have a Silverlight3 client consuming an unmodified/code-generated DomainService through RIA Services with a Linq-to-SQL back end. Is this the correct way to delete a row from the database? this.context.Albums.Remove(this.context.Albums[0]); this.context.SubmitChanges(); The SubmitOperation comes back with no errors, but no rows are...

Will using a transaction eliminate the need to use secondary dataContexts to attempt sql insert/update/deletes?

So I have a list of IT/developer tickets stored in a database via Linq-To-Sql. Save attempts are only done at the user request, or if they say save on close. My concern was that a user makes a change to 2 or more tickets without saving in-between. For some reason if the database rejects the change to one, doesn't give me very much info...

C# Linq syntax help - How can I exclude two values?

Hi all, I have this linq query that works well (although it may be written better, pls say so if you notice something) var qry = BenefitCodes .Where(b => b.BenInterest != 'E' && (b.BenProductLine == CoverageProductLine || b.BenProductLine == null) ) .Select(b => b) .OrderBy(b => b.BenDesc); A new requirement came ...

Xml query in LinqToSql

I have a XML column in a database and I'd like to query this XML using Linq(toSQL) in an efficient way. MyTable.Select(e => e.XmlObject.Element("Phone").Value) ... Seems this queries the db for XmlObject but process Element("Phone") part outside the database? How do I create the query so that native SQL XML functions are used? (Do I w...