linq-to-sql

Using LINQ with IBM i

Has anyone been able to use LINQ with the IBM i? That is without having to write a custom provider? ...

HowTo update/modify LINQ EntitySet?

In my LINQ to SQL generated classes I have some classes containing EntitySets. Everything looks great until I need to modify the EntitySet (add, delete some relationships). I thought that it was going to work doing something like: User.Actions = newUserActions; //This is how I used it with NHibernate Then when I try to submit chang...

How can i use Linq / Linq to Sql to do this?

Hi folks, I have an audit table and I'm trying to use Linq to figure out how to grab all the people's more recent audit actions. I'm just not sure how. Sample Schema Audit Table (technically it's actually a view) AuditId UserName Action CreatedOn 1 Bob Action1 2000-01-01 2 Bob Action2 2000-01-...

Operator == cannot be applied to Guid or int in Linq (MVC book example)

Working through the WROX "Beginning ASP.NET MVC 1.0" book I've hit a strange 'error'. "Operator '==' cannot be applied to operands of type 'System.Guid' or 'int'". The line in questions is: (p => p.ID_Officers == id).Single(); The full code is below, and Officers is my table, ID_Officers is my ID field. (I imagine that I could of us...

How does Linq Determine if a propety has a storage field?

I was looking at a dbml file in xml editor and noticed that some of the properties had a storage field and some did not. I also noticed that some had name, which I assuming is the name of the field in sql. If the property in the dbml file has a different name from the one in sql, it will add the member attribute. I don't understand wh...

What does "Member access 'DataType MemberName' of 'Namespace.ClassName' not legal on type 'System.Collections.Generic.IEnumerable`1[Namespace.ClassName]." mean?

I would love a solution to my current problem, but I would love EVEN MORE if I can understand what that error actually means. I have LINQ to SQL classes for two tables in my DB: Providers and Assignments. I added the following member to the Provider class: public IEnumerable<Assignment> Assignments { get { ...

What is the benefit of disposing of a LINQ to SQL DataContext?

What is the benefit of disposing of a LINQ to SQL DataContext? Or, is there a problem with not disposing of these DataContext objects? For instance, for easy coding, I might want to do something like... var list = from p in (new MyDataContext()).People where p.LastName.Contains("sommar") select p; In this case, I have new'd up an ins...

How can I see the SQL that is created from a LINQ to SQL query?

How can I see the SQL that is created from a LINQ to SQL query? The obvious answer is to open up the SQL profiler and look at it there. Is there a way in VS? Maybe there is a VS add-on like a visualizer that allows you to hover over the DataContext to view the SQL. ...

Id of object before insertion into database (Linq to SQL)

Hi, From what I gather, Linq to SQL doesn't actually execute any database commands (including the opening of database connections) until the SubmitChanges() method is called. If this is the case, I would like to increase the efficiency of a few methods. Is it possible for me to retrieve the ID of an object before inserting it? I'd rath...

Saving and retrieving inherited types with LINQtoSQL and Business Objects

I have an abstract EventBase class and some inherited event types, along with an Event class. Each event type has its own unique columns. In my data layer, I have a GetEvents method that simply does: from e in db.Events select new Event {...values...}; EventType is an enum which matches up to an EventTypes table I want GetEve...

Linq to Sql design and MVP

I'm experimenting with LinqToSql and the MVP pattern and having trouble setting on a good design. I'm using Asp.net 3.5 (not MVC) Here is a example public interface IMyBusinessCardView { string Field1 { get; set; } string Field2 { get; set; } string Field15 { get; set; } } public class MyBusinessCardPresenter { private...

Validate MVC 2 form using Data annotations and Linq-to-SQL, before the model binder kicks in (with DateTime)

I'm using linq to SQL and MVC2 with data annotations and I'm having some problems on validation of some types. For example: [DisplayName("Geplande sessies")] [PositiefGeheelGetal(ErrorMessage = "Ongeldige ingave. Positief geheel getal verwacht")] public string Proj_GeplandeSessies { get; set; } This is an integer, and I'm validating ...

Is this LINQ query with averaging and grouping by hour written efficiently?

This is my first real-world LINQ-to-SQL query. I was wondering if I am making any large, obvious mistakes. I have a medium-large sized (2M+ records, adding 13k a day) table with data, dataTypeID, machineID, and dateStamp. I'd like to get the average, min, and max of data from all machines and of a specific dataType within a 4 hour peri...

What type should I use with this aggregate query?

I am just getting my feet wet with LINQ to SQL, and need some advice in implementing a simple scenario: I have a method ListTagCounts that is doing an aggregate query with LINQ To SQL. I was not sure of the return type to use, so used the ToList() method and created a class just for the return type in order to get it to compile. Schema...

In LINQ-SQL, wrap the DataContext is an using statement - pros cons

Can someone pitch in their opinion about pros/cons between wrapping the DataContext in an using statement or not in LINQ-SQL in terms of factors as performance, memory usage, ease of coding, right thing to do etc. Update: In one particular application, I experienced that, without wrapping the DataContext in using block, the amount of me...

How to return multiple classes as IQueryable<T>

Using Linq I would like to return an object that contains customers and invoices they have. I understand returning a single type from a method: public IQueryable<customers> GetCustomers() { return from c in customers select c; } But I am having trouble figuring out multiple objects: public IQueryable<???> GetCustom...

What's a Linq query that will get each objX where objX.created = {newest}?

This one's turning out to be a brain teaser for me. I almost hate to ask for help for fear I might miss out on the endless, sleepless night trying to cypher this mystery. JK I've got a C# project where I need to display a list of unique objects, but only the newest one based on the type of object. For discussion purposes, let's talk "fr...

Why is my CONTEXT_INFO() empty?

I have a method that sets up my linq data context. Before it returns the DC it calls a stored proc that sets up the CONTEXT_INFO value to identify the current user. A trigger picks up any changes made and using this context data writes an audit record. I noticed that my context data was in the audit table blank so I wrote a simple unit...

Inserting extra data in a linq result but not to the data source or waiting for submiting changes on a context object

When I had a Typed DataTable with information retrieved from a SQL Server with a table adapter, I'm able to insert temporary data into that DataTable which I just want to use on execution time, and I don't want it to be inserted into the database. First supose that for example I have a Database table like this: CREATE TABLE MyData ( ...

Implementing trim for all string properties

Hi, We are using linq-to-sql entities,and want to implement trimming for all string properties.One way is on submitchanges,using reflection trim all string properties.Is there any other way? thanks ...