linq-to-sql

dynamic table name linq-to-sql dynamic LINQ

Hello Everyone, i want to construct my query dynamically based on the contents user has selected. and i want to do this in LINQ-t0-SQL. i have seen this. but i don't want to use sql statements with datacontext. on googling a bit i have a feeling that this can be done using dynamic LINQ. can someone quote some example of similar scenario...

how to query in linq to sql such way ?

Hi, I want to select the user. For this user I am marinating the designation Id which is foreign key in user table. as well as I am maintaining the ActiveStatus for soft delete. I want to select the user who are active , but instead of designation Id it must show designation name (like Director, Manager ..so on). How to join 2 tables an...

LINQ to SQL - How to "Where ... in ..."

I want to use linq to sort a resultset. The resultset should contain all items which has it's code also in the given array. To make this a bit clearer, in sql this should be: select * from tblCodes where CodeSort in (0, 2, 3, 5, 6) Now I want to do the same thing in LINQ but I can't seem to pull it off.. I've tried Contains, but that ...

SqlMetal alternative for Entity Framework 4

I used to prefer using SqlMetal to the OR Designer in Visual Studio when generating my Linq2SQL model. So, my question is: Is there an equivalent to SqlMetal for generating EF4 models, i.e. a command-line tool for rebuilding my EF classes in one step? ...

Derived class causes InsertOnSubmit() to throw NullReferenceException

I did look at the related posts that were answered, but still get the NullReference exception in InsertOnSubmit(). I have an auto generated LINQ class Transaction from which I create a derived class that overrides ToString(): public partial class MyTransaction:DataAccess.Transaction { public MyTransaction():base() { } ...

Linq query to display a proper sort order

Table 1: Lookups LookUpID LookUpName Desc DisplayOrder Table 2: BillingRates BillingRateID BillingRate ClientID LookupID I want the lookup name to be displayed (sort by Bill rate) DataContext DataContext1 = new DataContext1(AppSettings.ConnectionString); return ( from Lookups in DataContext1.Lookups join BillingRates in ...

What's wrong with this linqTOsql self referencing object mapping?

Hey there, I'm trying to create a self referencing object using linqTOsql mapping. So far, I am definitely in over my head. Here's the code I have: [Table] public class Category { [Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)] public Int64 catID { get; set; } public Int64 parentCatID { get; set;...

In generating a Linq to SQL class, how can I define a complex relationship?

I have two views: one is a normal view built from one table with an integer ID and other columns for the record (let's call it View1). I have another View (View2), which has an integer ID column and a second column named "table" (type: varchar). That second column contains the name of the table to which the ID column is related: So, i...

evaluating a boolean against a bit field in LINQ To SQL query

I am trying to do a simple little LINQ To SQL query against a SQL CE database. var result = from item in items where item.IsTrue == true select item; The problem is that the IsTrue property is a bit field in the database (bool in the CLR). When it goes to SQL in CE I get SELECT ... WHERE ([t0].IsTrue = 1).. ...

LINQ to SQL vs. SQL Server Reporting Services, which one is good enough for the following?

Basic reporting on content usage including time spent viewing a media asset, progress and interactivity based on % complete or correct for up to tens of thousands of users. Basic table and text based reports. Everything is in a SQL Server 2005 database. To me I don't feel like I should have trouble optimizing the LINQ to SQL to be good e...

Problem with mapping UDF using LINQ-to-SQL Designer

I'm trying to add a new table-valued udf to an existing LINQ-to-SQL designer in VS 2008. Everything goes fine and there are no compile errors or warnings; however when I try to execute the method I get the following error: System.InvalidOperationException: The method is not mapped as a stored procedure or user-defined function... I've...

Using Linq to Sql in C#, is there any way I can automatically truncate too-long data?

So, I'm importing data from one database into another. There are about 5,000 records (so nothing ridiculous, but not small enough to eyeball). Is there an easy way to automatically truncate data that is too long - specifically, varchar fields? I don't want truncation to be silent since the too-long fields will likely require attention, b...

Collection View Source and LINQ to SQL

Hi, I am trying to bind data in my WPF Application using CollectionViewSource and LINQ to SQL. I have the following code in my XAML <dbml:VendorsDataContext x:Key="vendorAddress1"/> <CollectionViewSource x:Key="addressViewSource1" Source="{Binding Path = tblVendor_Address ,Source={StaticResource ...

Iterating through IQueryable with foreach results in an out of memory exception.

I'm iterating through a smallish (~10GB) table with a foreach / IQueryable and LINQ-to-SQL. Looks something like this: using (var conn = new DbEntities() { CommandTimeout = 600*100}) { var dtable = conn.DailyResults.Where(dr => dr.DailyTransactionTypeID == 1); foreach (var dailyResult in dtable) { //Math here, res...

How can I find out the exact query that gets executed with LINQ to SQL in DbLinq and SQLite?

I'm using DbLinq with SQLite for a small project of mine. Is there any way to look at the actual SQL queries that get executed behind the scenes? I remember a monitoring program for SQL Server from my internship but SQLite is a quite different beast, I fear. ...

LINQ to SQL. Any prospects?

Hi2all! Can you tell me, please, what prospects of LINQ to SQL technology? Can I use it in my real projects, and for what kind of project I can use it (big or only simple projects, small db - about 30 tables)? Or it better now to use EF? So, can anybody explain me? Thank you. ...

Problem updating through LINQtoSQL in MVC application using StructureMap, Repository Pattern and UoW

I have an ASP MVC application using LINQ to SQL for data access. I am trying to use the Repository and Unit of Work patterns, with a service layer consuming the repositories and unit of work. I am experiencing a problem when attempting to perform updates on a particular repository. My application architecture is as follows: My service ...

Linq to Sql problem

I have 2 tables Users and Queries. They are connected via FK(UserId) in Queries table. I need to add queries added, for example, by user with login "Bob" to all users. Here is a chunk of code i'm using: public bool SaveUserQuery(string userName, Query query) { var db = new UserDataClassesDataContext(); Table<User...

ASP.NET MVC & Entity Framework: How to render a custom Model in a View ?

Hi, I have two tables Category 1..* Advertisement. I want to get the advertisements Count for each category. To do so, I use that query: var catList = (from c in DB.Category.Include("Advertisement") select new { c.Name, c.Advertisement.Count } ).ToList(); How to access the e.g the first element's p...

Complex Linq Query--Trying to add a .Where() or .Any() predicate to reduce query complexity (in VB)

I'm having issues with a rather complex Linq query and I need some advice. This involves VB syntax so I need specific answers for that platform, as I have a lot of trouble translating the C# syntax to VB at times. I have to join two main tables, and I need to filter the results by elements in an ASP.NET web form. These filters are c...