linq-to-sql

linq to sql OnLoaded() with SQL View?

I am trying to extend my Linq-to-Sql entity with a few extra properties. These are "calculated" properties based on data from the underlying SQL View. For example, think of having a Date of Birth field, which is used to calculate an extended Age field. I tried to extend my entity class by extending the OnLoaded() method. I get a comp...

Search for whole word with Linq to SQL

Hi, I'm using VB.NET and Linq to SQL to do search query. I'm using the Contains method of Linq to look up the input keyword. It's like this note.note_content.Contains(InputKeyWord). The problem is that If I search for the "cord" then "according" will also come up. I want the result to be matched with keyword only. How do I do to sear...

Should Business Logic objects have knowledge of their LINQ-to-SQL data objects?

I've looked at several similar questions but I didn't see any that directly applied to me, so forgive me if this is a duplicate. For separation of concerns I'm trying to somehow map my business objects with logic to the LINQ to SQL data objects in the .dbml file (fairly new to this btw). What its looking like though is that my business...

IQueryable, Where, Guid and

I'm working my way through the MVC Storefront code and trying to follow the path of a repository, a service and a model that is a poco, outside of the dbml/data context. It's pretty easy to follow actually, until I started writing tests and things failed in a way I just don't understand. In my case, the primary key is a uniqueidentifier...

Retrieve object from LINQ-to-SQL DataContext before SubmitChanges

I insert a new object into LINQ-to-SQL DataContext without calling SubmitChanges() yet: MyDataContext db = new MyDataContext(); MyObject newObject = new MyObject() { Id = 1, Name = "MyName" }; db.MyObjects.InsertOnSubmit(newObject); Now in another place in my code I want to retrieve this new object, even though it is not in the...

Implementing Linq-to-Sql Transactions Through WCF - Part II

I started here: http://stackoverflow.com/questions/753599/implementing-linq-to-sql-transactions-through-wcf Since then I came to the following. I am using basicHttpBinding for legacy, and my WCF client is unmanaged C++ (gSOAP). So I am using ASP.NET Session and enable aspNetCompatibilityMode on WCF. This works, so now I can handle sessi...

Noob in linq, selecting the first record of each record with the same value

Hi guys, im trying my best to learn LINQ but im still having a hard time coding it. Like this one, suppose I have a dataset or a List maybe and the names or fields of the of the collection object are the column names. Id | Date |Mon |Tues |Wed |Thu |Fri |Sat |Sun |Count 1 | 01/05 |=1=|==1==|==1=|==1=| 1=|=0=|=0==...

Which .NET Object Relational Mapper is fastest?

I want to use an Object Relational Mapper (ORM) tool for my ASP.NET application. I have three options: NHibernate, LINQ to SQL, and Subsonic. Which one is fastest? ...

LinqToSql: mutiple entity namespaces

Has anyone figured out a way to have more than one entity namespace within a single dbml? Different parts of my database are related to different things and I have them organized into different schemas. It would be handy if the schemas would translate to namespaces on the generated entities. There is no way to do this as far as I foun...

One all purpose (edmx./.dbml) or many depending on a criteria like domain, functionality??

Do you have one gigantic linq to sql DBML or Linq to entities .EDMX file / namespace or many files/namespaces separated logically?? For example in a db schema if you have 3 sub schemas like (Audit and UserMgmt), Human Resource, Sales..would you have them separated? ...

How to Combine two compiled queries? (Linq to Sql)

I have a series of linq queries. and I am stuck on combining these queries. Let's assume I have two simple queries. private static readonly Func(DataContext, string, IQueryable(Users)) CompiledQuery1 = CompiledQuery.Compile((DataContext context, string name) => from user in context.Table() where user.name == name select us...

Compiled queries and "Parameters cannot be sequences"

I thought that compiled queries would perform the same query translation as DataContext. Yet I'm getting a run-time error when I try to use a query with a .Contains method call. Where have I gone wrong? //private member which holds a compiled query. Func<DataAccess.DataClasses1DataContext, List<int>, List<DataAccess.TestRecord>> com...

How to get a dynamic top number of rows?

I want to get the top #nr_of_rows - (int)(#nr_of_rows / 10 - 1) of a table. So like if you have 63 rows, it would return 3 rows, 90 rows would return 10, 85 would return 5, etc.. Of course this can be done in two queries, just wondering if it can be done in one query. If you guys know of a straight sql query, it would be great but ideal...

Linq to Lucene: "The predicate of a Lucene Term can not be the empty string."

I am trying to implement Linq To Lucene in my project, but when trying to search for something, I am always getting a Enumeration yielded no results result and when I debug and try to open my [IndexContext].[TableProperty] in the Watch window, I am getting this message: The predicate of a Lucene Term can not be the empty string. ...

DataGridView bound to Linq to SQL does not show new rows added elsewhere to DB context

I have a DataGridView bound to a LINQ to SQL query expression. I want it to be editable for updates, but for inserts I want users to use separate controls below the grid (textboxes, date pickers, etc - currently not bound to anything). I have an "Add" button that creates an object of the linq to sql entity class based on the values in ...

Why Linq to Entities is more "hard" that Linq to SQL

Why in Linq to Entities do I need to specify relationships with Include(string)? Linq to SQL doesn't need to. Is this a choice of developers or limitation? Another problem, Linq to SQL is more "POCO" class, Linq to Entities is too complex. ...

C# Multiple Linq Query Search Issue

Hello, I have multiple linq queries for searching a database of information based on a single specific piece of criteria per query. e.g. by ID or by Name etc. Currently, the user can search by use of only one query method. The problem is that I want the user to be able to search using multiple criteria, without having to write new quer...

LinqToSQL and auditing changed fields

Here's another one of these LinqToSQL questions where I'm sure I must have missed the boat somewhere, because the behavior of the O/R Designer is very puzzling to me... I have a base class for my LinqToSQL tables, which I called LinqedTable. I've successfully used reflection to get hold of all the properties of the descendant classes a...

Extending DataContext entities - using InsertOnSubmit(this) inside "child" class

I am extending this DataContext entity, which looks sort'a like this: namespace Entities { public class User { public Int32 Id { get; set; } public String Username { get; set; } } } .. Like so: public class User : Entities.User { new public Int32 Id { get { return base.Id; } } pub...

Linq to SQL and Gridview Datasource

I have a question related to this one. I don't want to do a calculation (aggregation), but I need to get display values from an association. In my C# code, I can directly reference the value, because the foreign key constraint made Linq generate all the necessary wiring. When I specify the IQueryable as the Gridview datasource property, ...