linq-to-sql

LINQ2SQL - Combine multiple line-items into 1 row for reporting

Hello all, I'm working on a Ordering report, where an order can have no more than 5 items. So instead of displaying an Order row and 5 (or less) OrderItem rows below it, I want to combine them all into one row, so they looks something like this: Order # | Name | Address | Item 1 | Item 1 Qty | Item 2 | Item 2 Qty .... ... I've genera...

How to make LINQ to SQL backward compatible

Hi, I am new to LINQ to SQL.... I need to add a new column to an existing table and I updated the dbml to include this new field. Then in my C# code, I query the database and accessing this new field. Everything is fine with the new database; however, if I load back a previous database without this new field, my program would crash wh...

Get Birthday reminder Linq Query ignoring year.

Hi all Am using C# MVC and i need to get the user details who having birthday with in next 20 days. using linq to sql query which wants to compare only date and month and not the year, to fetch the users who having birthday within next 20days, anyone kindly help me with the linq to sql query to get the users who having birthday within n...

How have you combined the advantages of the direct View-to-Model approach and MVVM in your WPF projects?

In our application we have many Model objects that have hundreds of properties. For every property on the model: public string SubscriptionKind { get; set; } ...100x... we had to make an INotifyPropertyChanged-enabled property on the ViewModel: #region ViewModelProperty: SubscriptionKind private int _subscriptionKind; public int Sub...

How do I pass the query or results of a Linq to SQL query to the next method

Hi there, I have a Linq to SQl query in C# var queryGetAllPricingData = from i in dB.Invoices join c in dB.Contracts on i.ContractId equals c.ContractId where i.InvoiceStatusId == 100 se...

How can I filter choices out of a drop down list when using Dynamic Data?

I feel like this should be easy, but I don't see any way to do it. I'm using ASP.NET Dynamic Data with Linq to SQL. I've got a table with an Association to the Technician table. The Parent Property is TechAssignment, and on the web form I'm using a DynamicField to display it. This works fine really, it correctly sees it as a For...

Linq to Sql - Update all fields except primary key

I am trying to update a record in my database using Linq to Sql. I'd like to update all fields, which will come from a new object, however if I try this: originalObject = newObject db.submitChanges() It doesn't save the changes because it thinks the primary key has been changed (Or something along those lines.. it gives no error but ...

LINQ To SQL: Parent-Child Relationships Across Multiple DBML Files

In our app, we have a DBML file for each schema in our database. There doesn't appear to be a way to establish a parent-child relationship when the parent table is in one DBML and the child table is in another DBML. At least not without writing some custom code. How is this generally done? Thanks - Randy ...

Can you implement an interface on a Linq2Sql class?

I have an interface called IAddress, and a class called Address that handles street, city, state/province, postal code and country. I have a couple of Linq2Sql classes that has all the address information and would like to implement the interface IAddress, and pass that in to the constructor for Address that would the load the property v...

LINQ to SQL: Read entity while calling "SubmitChanges" causes DuplicateKeyException

Hi, I'm experiencing a strange behavior that I really don't know how to work around it. I'm trying to read an entity just after it has been inserted (right after the ExecuteDynamicInsert) and when the partial method returns, I always get a System.Data.Linq.DuplicateKeyException "The database generated a key that is already in use.". H...

modifying Linq-to-SQL connection in dbml?

Am I understanding correctly, and the database connection string for Linq to SQL is typically stored in the app.config file, in the connectionStrings section? Are there other places it might be done, typically? Thanks! ...

Mapping a URI to String-field in LINQ-to-SQL

I'm trying to store a URI as a string in a database, using LINQ. [Column(Name = "Url", DbType = "nvarchar(255)")] public Uri Url { get { return new Uri(_url); } set { _url = value.AbsoluteUri; } } private string _url; This maps nicely to my database design, however, when trying to fetch data u...

Linq-To-Sql issue with datetime?

Ok, I'm using SQL Server Express 2008 and .Net 3.5 (c#) I have a couple of datetime fields in the database and am trying to make an edit to a row (Using Linq-to-Sql) I receive the error "Row not found or changed." I have spent some time getting the generated SQL and it seems that the issue is caused by the milliseconds attached to the ...

Linq2sql groupby concat

I have an expression that returns the following data ID Name Date 1 BRN 01/12/2009 00:00:00 1 BRN 01/06/2009 00:00:00 2 WTI 01/12/2009 00:00:00 2 WTI 01/06/2009 00:00:00 I'd like to add a group by ID and Name and then concat the two dates together with a hyphen seperating. My only solution so far is to get all the data th...

Prefetching data in with Linq-to-SQL, IOC and Repository pattern

Hi, using Linq-to-SQL I'd like to prefetch some data. 1) the common solution is to deal with DataLoadOptions, but in my architecture it won't work because : the options have to be set before the first query I'm using IOC, so I don't directly instanciate the DataContext (I cannot execute code at instanciation) my DataContext is persis...

How can I read an uploaded Excel file and save it direct to DB?

Hi! Is there a way to upload an Excel file and save its content to Sql Server directly? thanks!! EDITED: I don't want to save it as binary. I want to read its contend and save them to DB, each Excel column content into the DB table column and so on... ...

How do I handle a failed SubmitChanges in LinqToSql?

If the db.SubmitChanges failed for whatever reason, I want to return a failed message. DO I just catch the error or does the ConflictMode help here? ...

Linq to SQL Insert Error

An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported. This is the error message I am getting when I try to run the following, roughly: 1 DataContext db = new DataContext(); 2 o = new object(); 3 o.association = db.GetAssociatedObject(p...

Linq not updating changed class property

First of all, I have read the similar posts and don't see how they solve this problem. If I'm missing something in them, please point out what. My Linq code is very similar to Scott Gu's expensiveUnpopularProducts example. However, in my case, the database is not being updated with the new value. There are no exceptions raised, and a...

About primary key in the table?

I would like to have some explaination about the characteristics of a primary key in the table of such database.This is for vb 2008 express edition,since im new to this language,if this is true, as far as i understand about the characteristic in setting the primary key on each field for true.My question is if you are doing an updates/edi...