linq

LINQ many-to-many relationships: Solution?

LINQ so far has been remarkably elegant, but to perform basic m2m queries it offers no solution I can imediately see. What's worse is that while it works for any other table relationship, LINQ is not giving me an association in the class structure for my m2m table. So I can do things like artwork.artists.where(...) //or artist.Artwo...

Adding a method call to a Linq Expression whilst remaining an full expression

How I do extend an linq expression whilst keeping it an expression? I've simplified this quite a bit (to avoid pasting pages) - .e.g I working with Queryable rather than Enumerable, but the solution for this will suffice, ultimately I need to keep it as an expression whilst adding a method call to it. For exampleL var p1 = new...

System.FormatException: String was not recognized as a valid DateTime.

Hello all, I am using c#.net. Thanks in advance for any help. I am using a Repeater and a ObjectDataSource. I use LINQ to connect to the database. This requires a parameter to be passed through (used within the WHERE clause) public IQueryable<comments> GetComments(DateTime todaysDate) { return (from c in dc.comments ...

XDocument/Linq concatenate attribute values as comma separated list.

If I have the following xml: XDocument xDocument = new XDocument( new XElement("RootElement", new XElement("ChildElement", new XAttribute("Attribute1", "Hello"), new XAttribute("Attribute2", "World") ), new XElement("ChildElement"...

LINQ syntax where string value is not null or empty

I'm trying to do a query like so... query.Where(x => !string.IsNullOrEmpty(x.PropertyName)); but it fails... so for now I have implemented the following, which works... query.Where(x => (x.PropertyName ?? string.Empty) != string.Empty); is there a better (more native?) way that LINQ handles this? EDIT apologize! didn't include t...

Linq To Sql and identity_insert

I am trying to do record inserts on a table where the primary key is an Identity field. I have tried calling mycontext.ExecuteCommand("SET identity_insert myTable ON") but this doesn't do any good. I get an error saying that identity_insert is off when I submit changes. How can I turn it ON from the c# code before I submit changes? E...

Adding behavior to LINQ to Entities models

What's the preferred approach when using L2E to add behavior to the objects in the data model? Having a wrapper class that implements the behavior you need with only the data you need using (var dbh = new ffEntities()) { var query = from feed in dbh.feeds select new FFFeed(feed.name, new Uri(feed....

conditional assignments in Linq to SQL methods

How do I do something like the following, assinging new values based on condition within a linq method but keeping all results. int x= 100; var results= from r in Results where r.id==id select r { if r.value==x set r.result="Found"} ...

Getting "select permission denied" when using LINQ but my account is a sysadmin

I have a console app that's geared to be automatically ran as a Scheduled Task. I use LINQ to SQL to pull some data out of the database, format it into a CSV and email it to a client. All of a sudden I am getting the error "SELECT permission denied for table", but the account I'm using to connect to the database (specified in my app.co...

Default Values in LINQ Modelling

To put it in basic form, my database table doesn't allow nulls for varchars, it must have blanks. My model doesn't allow nulls so it won't insert a record if I leave form fields empty. If an empty form field appears I want a default value of blank to be used instead. I've tried, for example, the following without any luck: [Column] [...

Linq query for data aggregation

I have this class public class Line { public string ConnectionsIndex{get;set;} } my Linq problem is that I have to aggregate these Lines var l1 = new Line{ ConnectionsIndex="01,02"}; var l2 = new Line{ ConnectionsIndex="02,03"}; var l3 = new Line{ ConnectionsIndex="01,03"}; into this var l4 = new Line{ ConnectionsIndex="01,02,03...

Parsing XML Data with LINQ

I am new to LINQ and there is an urgent need to finish this project quickly. I need to return the id with the correct price information for todays date for each MPrice. Any advice is well appreciated! Here is an example of the XML: <Pricing> <MPrice> <Id>0079</Id> <Price> <Price>31.25</Price> <StartDt>2009-8...

Entity Framework 3.5 - How to load children

My questions is probably very simple, how do you load children/subclasses. There is no "load" or anything like it that I can find to have the context load the children. the context class is of ObjectContext type, see below: public partial class RTIPricingEntities : global::System.Data.Objects.ObjectContext Product Product.Mo...

Auditing in Entity Framework.

After going through Entity Framework I have a couple of questions on implementing auditing in Entity Framework. I want to store each column values that is created or updated to a different audit table. Rightnow I am calling SaveChanges(false) to save the records in the DB(still the changes in context is not reset). Then get the added ...

save new or update exist record with linq

this is the way i used to save record with linq: (my Q is below) public void SaveEmployee(Employee employee) { using (BizNetDB db = new BizNetDB()) { BizNet.SqlRep.Data.Employee oldEmployee = (from e in db.Employees where e.EmployeeID == employee...

NHibernate Second Level Cache With NHibernate Linq Provider 1.0

How to enable NHibernate Second-Level Cache with NHibernate Linq Provider 1.0 ? Second-Level Cache seems to work only with ICriteria usage. ...

Group by variable integer range using Linq

I'm trying to group a set of data based on the range of an integer, by the range does not increase at a fixed interval. e.g. I have Item ID Price 1          10 2          30 3          50 4          120 I would like to group the items with price 0 - 10, 11- 100, and 100-500. So that item 1 ...

How do I add an xml file to my project?

I'm trying to start out with LinqtoXml. I have added (I think) the right namespaces XElement contactsFromFile = XElement.Load("App_Data/test.xml"); Doesn't work... I get a "Could not find a part of the path 'C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\App_Data\test.xml'" error... Please help. ...

LINQ to Object Query

I need help with a specific LINQ query (I still suck at em'!) Background Info: I've got a class DataEntry: class DataEntry{ public Attribute Attribute{get; set;} public List<object> Data{get; set;} Attribute Class: class Attribute{ public string FeatureName{get; set;} public Types FeatureType{get; set;} public L...

Do I need to call InsertOnSubmit for every row that references a main row?

LINQ to SQL - When inserting a row (and several other rows with FKs that will point to the PK on this row), is it sufficient to execute [context].[MainTable].InsertOnSubmit(row), or do I need to call it for the other rows as well? Here's a condensed code sample (C#): //Forgive the contrived example (off the top of my head) :) //Main r...