linq-to-sql

"Where" Linq capability in my own application

I need to have "Where" Linq functionality in my own code. Let me explain: we have an application that lets users write the so-called "user code", which is code in C# that will be picked up by the app and compiled and run at runtime. In user code, I need to be able to specify an SQL condition. A special case is the condition on a date...

Linq Sort Nested Table

Follow up question to this: http://stackoverflow.com/questions/1488414/linq-combine-left-join-data Say I have the following db tables: Users ------- UserId (PK) UserName Roles ----- RoleId (PK) RoleName UserRoles --------- UserId (PK) RoleId (PK) Users 1-M UserRoles M-1 Roles Using LinqToSQL, I can return the following set (thanks...

linq function for use with generic repository entity in where clause

Hi, I want to use a generic repository to standardise some of my data access. What I want is to be able to have a function defined in the interface representing the basic fields of my entity, so that I can use it to filter the results. This should be compilable into Linq-To-Sql. e.g. interface IEntity { Expression<func<bool>> Filter...

Linq Sort Direction From String

I am trying to sort a set of Users. I have access to the sorting property and direction (asc, desc). My current order by query is below. But as you can see it doesn't account for the sort direction. How do can I build this expression without having to use Dynamic Linq, or adding another set of statements for "asc" or "desc" sort directio...

ASP.NET reference a LINQ to SQL class in Silverlight from its origin in the models of MVC?

I am working on an mvc app that uses some silverlight to supplement a page and instead of having to maintain two separate linq to sql classes I want to add a reference to the main project from the silverlight project but this can't be done through the normal method of just adding a reference, anyone have a workaround? ...

What would cause a SqlDateTime overflow when using LINQ to SQL SubmitChanges()?

In my code I have multiple objects being added to the repository, I have tried running the repository Save() function one time at the end of all the loops, and also calling it after every object that is added. But either way I still get a SqlDateTime overflow when the db.SubmitChanges() in the repository .Save()... any idea? SqlDateTim...

Remove Entity from DataContext so that its not inserted (Linq-to-SQL)

In my application I have 2 entities that are defined as: public class A { public B ClassB { get; set; } // Bunch of code } public class B { // Bunch of code } When I create a new instance of class A, assign it a new instance of B and insert A into the DataContext, the instance of B is also inserted into the DataC...

LinqPad, using multiple datacontexts

I am often comparing data in tables in different databases. These databases do NOT have the same schema. In TSQL, I can can reference them with the DB>user>table structure (DB1.dbo.Stores, DB2.dbo.OtherPlaces) to pull the data for comparison. I like the idea of LinqPad quite a bit, but I just can't seem to easily pull data from two d...

Convert T-SQL to LINQ-to-SQL

I have a table ContentHistory in a SQL Server 2008 database with a column Content of data type xml, NOT NULL. This column stores complete XML documents (an Intersection root node containing one or more Article nodes: <InterSection> <Article> <ID>1</<ID> ...other nodes/data </Article> <Article> <ID>2<...

why this Linq to sql function return nulls?

I am new to linq to sql I wrote this function: public ICollection<ICustomer> GetAll() { DataClasses1DataContext context = new DataClasses1DataContext(); var customers = from customer in context.Customers select customer; return customers.ToList().Cast<ICustomer>().ToList(); } But it always return list of null values. The...

Linq2SQL: Optimize query?

Can I optimized the following query in any way: The goal is to try to find clients of type 4 that also exists as type2 based on their VAT and Email. A client can have one or more clientusers. (I have all the appropriate indexes set, I promise) from e in Clients.Where(h => h.ClientTypeId==4) join u in ClientUsers on e.Id equals u.Clie...

How to add sub-entities in Linq to SQL?

I have two Linq2SQL objects, Order and OrderLine. An Order contains multiple OrderLines. I created a constructor Order(Reservation reservation). The idea is that this constructor generates a new order and the orderlines that it should contain. I have this code: public Order(Reservation reservation) { this.date = DateTime.Now; ...

C#, Linq to Sql: Why can I not use an expression to filter SubEntities?

I have made myself an ExpressionBuilder class that helps me put together expressions that can be used as a predicate when doing Linq to Sql queries. It has worked great. However, I just discovered Expressions can only be used to filter on Tables, and not on EntitySets??Why on earth is this the case? For example if I have Company and an ...

Linq to Sql - Double Group By with Parent Table Relation

I'm having a trouble getting a linq to sql query and was wondering if someone could help. I have these tables: 'Orders', 'OrderProducts', 'Products' and 'Users'. I want to get a breakdown of the count of how many products (contained in 'OrderProducts' by ProductID) each 'User' has ordered. The User's UserID is contained in the 'Orders...

Linq caching data values - major concurrency problem?

Here's a little experiment I did: MyClass obj = dataContext.GetTable<MyClass>().Where(x => x.ID = 1).Single(); Console.WriteLine(obj.MyProperty); // output = "initial" Console.WriteLine("Waiting..."); // put a breakpoint after this line obj = null; obj = dataContext.GetTable<MyClass>().Where(x => x.ID = 1).Single(); // same as before, b...

Linq2Sql - Adding multiple Contains IQueryables to a base IQueryable will change every previous IQueryable to the last IQueryable Expression added to the Linq2Sql query. Am I off my rocker?

I am spending a good amount of time trying to figure out why Linq2Sql is changing my SQL query. It is rather difficult to explain, and I cant find any reason why this is happening. The low down is it appears that adding multiple contains around an IQueryable seems to overwrite each previous IQueryable Expression. Let me try and explain...

help with linq to sql

Help me with this algorithm please. var companies = companyrepository.GetAll().OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize); string where = ""; if (op == "eq") where = field + "=" + data; else if (op == "cn") where = field + " LIKE '%"+data+"%'"; ///here lies my problem companies = companies.Where(where); ...

Is LINQ-to-SQL + SQLite.NET + Stored Procedures + VISUAL STUDIO 2008 possible?

Hi. So I want to retrieve data using stored procedures. Preferably via Linq2SQL. So I can do something like this (example): var productHistory = dbname.StoredProcedureMethod(value); foreach(var product in productHistory) { //stuff } This is something I'd like to be able to do in Visual Studio 2008 in .Net 3.5. It is possible wit...

What's the difference between a double? and a double and why can't I implicitly convert them?

Visual studio is yelling at me, in the database it is a float, and in my class it is a double. Why can't I assign it and why does it think it's a 'double?' ? LINE THREE BELOW Confirmation confirm = new Confirmation(); confirm.order = theOrder; confirm.totalPrice = theOrder.BillingAmount; HERE IS Confirmation DEF pu...

How do you persist changes to objects returned from a LINQ query to the database?

So I load up an object like... MyObject object = new MyObject(); object = objectRepository.getObjectByID(id); object.lastLoaded = DateTime.Now(); ... //NOW WHAT???? I know there is a .Save() but does that update the current one or is that only used for creating new ones? ...