linq-to-sql

Linq2SQL Reference Types

I have an object with a NameValueCollection property which I'm managing with Linq2SQL. I was going to serialise it to an XML column (xelement) in the DB. My problem is I don't really have a hook to convert it to XML on save with Linq2SQL. I believe I can use the OnLoaded partial method to control the deserialisation. Does anybody hav...

Adding Constant where clasue to Linq to SQL mapping

Is is possible to put a constant where clause to a Linq to SQl mapping. I really don't want to do this at the query level or in my Data Access Object as these are currently completely generic and would like to keep it that way to make life for the other developers and save me repeating myself constantly. Colin G ...

Linq to SQL - "This member is defined more than once" error.

I have the following linq code... CMSDataContext dc = new CMSDataContext(); var q = from u in dc.CMSUsers join d in dc.tblDistricts on u.DistrictCode equals d.District into orders select u; District shows this error: Ambiguity between 'tblDistrict.District' and 'tblDistrict.District' Any ideas? EDIT: It ...

Is everyone here jumping on the ORM band wagon?

Microsoft Linq to SQL, Entity Framework (EF), and nHibernate, etc are all proposing ORMS as the next generation of Data Mapping technologies, and are claiming to be lightweight, fast and easy. Like for example this article that just got published in VS magazine: http://visualstudiomagazine.com/features/article.aspx?editorialsid=2583 Wh...

Reading from dynamically created tables with LINQ

We create tables in runtime. They have the same schema layout as tables that exist in our DBML but with an alternate name. We want to set the table names in runtime in our use of Linq to Sql. Using wrapper classes on the Metadata as outlined in https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=4233721&SiteID=1 works great for t...

Linq 2 SQL or Linq Entities

I am starting to design a new application and what I am wondering is peoples opinions on Linq2SQL or Linq2Entities and what they feel is the better technology for rapid development. I am also doing some research into ADO.net data services. ...

LinqToSql overriding insert with inner classes C#

I have a base recipe class and I am using a datacontext. I overrode the insert method for the recipe in the datacontext and am trying to insert into its children. Nomatter what I do I cannot get the child to insert.Currently, just the recipe inserts and nothing happens with the child. partial void InsertRecipe(Recipe instance) {...

Is linq a cursor?

I'm familiar with .NET and with SQL. Now I'm looking at the new LINQ and it looks to me just like a cursor. I understand the ease of use, etc., but if I do a LINQ-to-SQL query with a foreach loop, am I just using a DB cursor? Or is there some sort of magic behind the scenes where LINQ collects all the data at once and feeds it to my p...

LINQ to SQL

While trying to use LINQ to SQL I encountered several problems. I have table persons: int ID string firstName string lastName And table notes that has: int ID string noteText string createdBy datetime creationDate int PersonID PersonID is a foreign key and the relationship is 1:n I tried to use LINQ to SQL to create a person an...

LINQ to SQL auto-generated Extensibility Methods

When I generate entity classes using LINQ to SQL I get what I want but I get also a bunch of other Extensibility Methods Definitions. For Example for myField (TEXT) I get: partial void OnMyFieldChanging(string value); partial void OnMyFieldChanged(); What's a common use for the extensibility methods above? ...

What part of LINQ to SQL's provider model makes it impossible to extend it to support third party (read: Non-Microsoft) databases?

There were supposedly some classes in the LINQ to SQL provider model that were sealed--but I never really figured out exactly which classes need to be 'unsealed' in order to use it. Hypothetically speaking, which classes do I need to unseal to enable the provider model? [EDIT: I know that the sealed keyword means that it's not supposed...

Linq to SQL Nested IN FROM query

Can anyone tell me how to write a nested SQL query like SELECT * FROM X WHERE X.ID IN (SELECT Y.XID FROM Y WHERE .....) in LINQ? ...

How to create a reference to an existing record

Hello, go easy on me, it's my first question :) I've been working with linqToSql for about a month, and there is just this one thing that is bothering me... Lets say I have an Entity Object called "Customer" and another called "CustomerType", Customer as a reference to CustomerType. When inserting the Customer I need to set the Custum...

How can this Linq2Sql create an enum in the select clause?

Hi folks, i've got the following linq2sql query, and i'm setting the result to a POCO. One of my POCO properties is an enumeration. public IQueryable<Models.Achievement> GetAchievements() { return from a in _sqlDatabase.Achievements select new Models.Achievement { // Note: ToEnum is an extension ...

Linq2Sql Many:Many question, How would you do this?

I know many:many isn't supported in Linq2Sql but I am working on a workaround I am working with my little SO clone and I have a table with Questions and a table with Tags and a linking table QuestionTag so I have a classic many:many relationship between Questions and Tags. To display the list of Questions on the front page I have this...

Access LINQ-2-SQL DataContext in entity class

Is there any simple way to access the DataContext in a linq2sql entity class. I'm trying to create something like EntitySet but I cannot figure out how the EntitySet has access to the context that created the entity object in the first place. I want to have a regular linq2sql entity class with a way for the class to access the DataCont...

C#: Is it possible to declare a local variable in an anonymous method?

Is is possible to have a local variable in an anonymous c# methods, i.e. in the following code I would like to perform the count only once. IQueryable<Enquiry> linq = db.Enquiries; if(...) linq = linq.Where(...); if(...) linq = linq.Where(e => (x <= (from p in db.Orders where p.EnquiryId == e.Id select p).Count() && (fro...

LINQ Error Invalid Column Name on Group by sum.

For some reason, when using two sums on a group by, i run into the error "invalid column name 'id'. When i only do one sum, it works as expected. The following fails and throws the error: from pd in PrDetails.Where(_pd => _pd.PrId == 46) group pd by new { pd.ProgramFund, pd.ProjectDetail.CostCenter, pd.ProjectDetail.Wbs } into g sele...

Get Id using LINQ to SQL

Hi everyone, How can I get a record id after saving it into database. Which I mean is actually something like that. I have Document class (which is entity tho from DataBase) and I create an instance like Document doc = new Document() {title="Math",name="Important"}; dataContext.Documents.InsertOnSubmit(doc); dataContext.SubmitChanges...

How do i populate a POCO (child) IList property from a Linq2Sql query?

Hi folks, I have a two classes: public class Question { public IList<Answer> Answers { get; set; } } public class Answer { .. } In my Linq2Sql designer, there's two L2S objects on designer, with the correct 0<->many arrow between them. Kewl. I'm not sure how i can retrieve these questions/answers in a single call and populate m...