linq-to-sql

Linq2SQL: Always get .Sum() to return 0 instead of null

Is there any way (through a extention mechanism?) to get the Sum() function to allways return 0. My workaround now is to write like this, but I'm hoping there's a better solution? ((int?)e.CampaignCodes.Sum(f => f.Enquiries.Count()) ?? 0), ...

LINQ to SQL: Return anonymous type?

Using the simple example below, what is the best way to return results from multiple tables using Linq to Sql? Say I have two tables: Dogs: Name, Age, BreedId Breeds: BreedId, BreedName I want to return all dogs with their BreedName. I should get all dogs using something like this with no problems: public IQueryable<Dog> GetDogs(...

Unsupported overload used for query operator 'Intersect'.

I am able to do this query just fine with the test repository which is In Memory when I move to the sqlRepository I get this error Unsupported overload used for query operator 'Intersect'. I assume it is because sending the query to sql is too complicated for Linq to Sql to do when it is not dealing with the Model.Model.Talent Type. I...

LINQ Join On Between Clause

Hello All, I am having some issues throwing together a LINQ query that will join a table based on a zip code. I need to join the table based on whether the customer's zip code lies with in a range of zip codes that is determined by ZIPBEG and ZIPEND columns. The T-SQL would look something like this: JOIN [ZipCodeTable] [zips] O...

Adding new methods to LINQ to SQL generated classes

I am new to LINQ. I just dragged all my database tables onto the designer in a LINQ to SQL dbml. All my relationships are correct and look nice in the designer. I am able to pull data using simple LINQ code. I want to add my own methods now but don't want to blow away my changes if (when) I need to regenerate my dbml. I am guessing ...

Linq-to-Sql: recursively get children

I have a Comment table which has a CommentID and a ParentCommentID. I am trying to get a list of all children of the Comment. This is what I have so far, I haven't tested it yet. private List<int> searchedCommentIDs = new List<int>(); // searchedCommentIDs is a list of already yielded comments stored // so that malformed data does not ...

LINQ Resultset Issue

I built a site using LINQ and it has started to show issues with the results it brings up. The results brought out by the query do not reflect the data in the database, they reflect an older version of the database. In all the places where the LINQ data context was created it was disposed off properly. The sample code used in the sit...

resource for learning about predicates

are there any good tutorials online for learning about the c# 2.0 language feature "predicates"? i'm trying to learn how to use predicates along with linq to sql to modify my queries what i am trying to do is query a table of customers and filter it based on changing criteria. for example find all customers who have zipcode = 90210 f...

Entity attachment issues in LINQ

I am trying to attach a LINQ entity to the data context after I receive it from a form POST. However, all I get is the following exception: An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy. I have also tried attaching the original row, like so: d...

Localisation/I18n of database data in LINQ to SQL

I have status tables in my database, and "localised" tables that contain language-specific versions of those statuses. The point of the main status table is to define the status ID values, and other meta-data about the status. The "localised" table is to display the text representation in a UI, according to the users' preferred languag...

Linq to SQL vs Entity Framework, Microsoft support for

What are the pros/cons of both? Also, I've heard various rumors concerning if Microsoft will continue to support LINQ to SQL, any further info on this would be appreciated. ...

C#: Comparing two Linq2Sql entities not working?

Could anyone explain to my why this is not working? In the database we have Employees with an IdEmployee column. We also have some tables with foreign keys to that one. Say we have something like this: var employee = dataContext.Employees.First(<some predicate>); var someEntity = dataContext.SomeEntities.First(<some predicate>); Wh...

Inserting item in LINQ to SQL datacontext - doesn't appear until application restart

I have an ASP.NET MVC (using the release candidate) application that works with a class library that among other things uses LINQ to SQL for data persistance. One of the thing the app/db maintains, is the concept of a "Folder" - like a disk folder, but with a hierarchy that only exists in the database. Other database objects live in the...

Is it a best practise for a database to allow apps do CRUD operations always through SPs?

I've heard reasoning behind this and I was curious if others think of this as a best practise/good idea. One reasoning is, that putting restrictions on direct access to database tables, and forcing apps/users to use SPs (Stored Procedures) to do CRUD operations will allow DBAs fine grained control to approve/review SPs before moving ...

Dynamic Table Names in Linq to SQL

Hi all I have a horrid database I gotta work with and linq to sql is the option im taking to retrieve data from. anywho im trying to reuse a function by throwing in a different table name based on a user selection and there is no way to my knowledge to modify the TEntity or Table<> in a DataContext Query. This is my current code. publi...

LINQ to SQL extension method for sorting and paging

I have found an extension method that handles sorting and paging for LINQ. While this works well, I am trying to see if there are some other ways I can use this. At present, the code for the extension method is as follows: public static IQueryable<T> Page<T, TResult>( this IQueryable<T> obj, int page, int pageSize, System.Li...

Put logic behind generated LinqToSql fields

In a database I use throughout several projects, there is a field that should actually be a boolean but is for reasons nobody can explain to me a field duplicated over two tables where one time it is a char ('Y'/'N') and one time an int (1/0). When I generate a datacontext with LinqToSql the fields off course gets these datatypes. It wou...

IMultipleResult.GetResult<>() truncating result data

hi I am calling a stored procedure using Linq2Sql, and the sp returns a long xml string as the result, from a select statment. I'm using IMultipleResults.GetResult<>() to retrieve the string. Everyting is fine except when the Xml string is too long, and the GetResult returns only a partial output. Is there any constraint on IMultiple...

How do I Validate a User Using LINQ to SQL?

Hi , I'm trying to work out how to validate a user in my application but i don't know how. I wish create a form with Username and Password to enter in the application(WPF) using Linq toSql to store and validate Username and password in the database but i don't know so much about Linq to Sql so i keep in stuck now. I have a database with...

Linq to SQL Inheritance Question

I guess I'm not quite sure how the Linq inheritance is supposed to work. I have a "User" entity and I want to have two additional entities called "Creator" and "Assigned" that inherit from the "User" entity (basically they should just have the same exact properties as the User entity) I don't need any additional properties. I can do th...