linq-to-sql

Linq-To-SQL Invalid Cast on insert, not on update ...

Hey guys, I'm having a weird time with Linq-To-SQL I'm building a postit system that allows people to make postits and attach them to multiple objects. The database for this is a table that has the postits themselves (id, message, etc) and a linkstable which holds the records to which a postit is attached. the weird thing I'm experianc...

Can anyone recommend good tutorial on repository and Unit Of Work pattern usage for TransactionScope with linq ops.in C#?

Can anyone recommend good tutorial on repository and Unit Of Work pattern usage for TransactionScope class with Linq ops.in C#? ...

Overwrite DataContext methods in LINQToSQL

Hi, I am new to LINQToSQL. Is there a way to overwrite the "InsertOnSubmit" or "DeleteOnSubmit" methods of the DataContext class for a particular entity? Like for example, I have a database table called Customers that has a boolean field "IsDeleted" which holds true if the user deletes a customer record from UI. If I will call the _myDa...

Getting value from VAR

For the following code var validate = from P in this.DataContext.Persons where P.UserName.Equals(login) && P.Password.Equals(password) select new { P.FirstName, P.LastName, P....

How Can I get return values returned by stored procedure using InsertOnSubmit in LINQ

Can I get return values returned by stored procedure using InsertOnSubmit in LINQ. The stored procedure return a error number. How can I get this error number InsertOnSubmit (using stored procedure instead of Runtime sql). Many Thanks ...

Date Conversion problem-LINQ2SQL

How to convert convert(varchar,datefield,106) of SQL's in LINQ? Thanks in advance ...

Simplest way to use a DatagridView with Linq to SQL

Hi, I have never used datagrids and such, but today I came across a simple problem and decided to "databind" stuff to finish this faster, however I've found that it doesn't work as I was expecting. I though that by doing something as simple as: var q = from cust in dc.Customers where cust.FirstName == someString se...

How do I implement a dynamic 'where' clause in LINQ?

I want to have a dynamic where condition. In the following example: var opportunites = from opp in oppDC.Opportunities join org in oppDC.Organizations on opp.OrganizationID equals org.OrgnizationID where opp.Title.StartsWith(title) select new ...

LINQ to SQL replacement in .NET Compact Framework

I have been tasked with porting our .NET Desktop application to a mobile device. Our desktop application uses LINQ to SQL to interact with the database. However, LINQ to SQL is not available on mobile devices. We develop for Windows Mobile 5 and 6. I am debating between suggesting a different ORM that supports both desktop and mobile...

Linq to Sql + custom data types

Hello, I have a custom asp.net control i created that allows you to bind an object to it, it functions kinda like a winform propertygrid. Heres my issue: the control looks at the public properties and types of the class, if it detects a type of color it renders a color picker, etc.. Works great for classes that i create - however not...

How to use DateTime in WHERE clause (LINQ)?

How to add date is where clause. I am using following code. var opportunites = from opp in this.DataContext.Opportunities join org in this.DataContext.Organizations on opp.OrganizationID equals org.OrgnizationID select new ...

How to retrieve an Image from MS SQL Server to bind in Gridview ASP.NET by using LINQ to SQL?

I have a binary file which stores in the customerPicture column that has Image as a datatype in the CUSTOMERs table. I have saved an image by using this line of code in LINQ to SQL. Dim db = new MyCompanyDataContext Dim newCus = new CUSTOMERs Dim filebyte As Byte() = fileUploader.FileBytes Dim fileBinary As New System.Data.Linq.Binary(...

LINQ to SQL Table List to Interface List

I have the following code: public IQueryable<ITax> FindAllTaxes() { return db.Taxes; } I am getting the following error Cannot implicitly convert type 'System.Data.Linq.Table<Models.Tax>' to 'System.Linq.IQueryable<Interfaces.ITax>' I am trying to use Interface where ever I go, but not sure how to convert this, any help? ...

Extending System.Data.Linq.DataContext

I have a class reflecting my dbml file which extends DataContext, but for some strange reason it's telling me System.Data.Linq.DataContext' does not contain a constructor that takes '0' arguments" I've followed various tutorials on this and haven't encountered this problem, and VS doesn't seem to able to fix it. Here's my implemen...

LINQ to SQL how to get value by field name

I use Linq to SQL as data access layer in ASP.NET MVC application. So the query result is a strong typed object. How can I dynamiclly specify which field to show in the page. For example, the query result has the following fields: FirstName LastName Address Tel My question is if one user wanna show the Lastname and the Firstname. 2nd u...

How do I use my enumeration in a LinqToSQL query?

I have a field in my database table that use to store an enumeration value, e.g.: create table MyTable ( ... Status tinyint not null, ... ) and in my C# class I have public enum TStatus : byte { Pending = 1 Active = 2, Inactive = 3, } public TStatus MyStatus { get { return (TStatus)Status; } set { Status = (byt...

...is not a foreign key column and cannot be used here?

I have two views in SQL, and have created mappings to them in Linq to SQL. The two views have an association, which works fine, between Ticket.ProblemCode and Problem.Code When I try to set UIHint("ForeignKey") on Ticket.ProblemCode and run the web page I get the error: 'ProblemCode' is not a foreign key column and cannot be used here...

Why is ForeignKey_Edit loading primary key as the value, instead of the actual value used in the association?

I'm using ASP.NET dynamic data to create a ticket edit form. The Ticket is associated to a problem code, but not using the problem code's primary key. (The database is 3rd party, so I don't have control over that...) So the problemCode looks basically like: ProblemCode ( ID int, Code varchar(8), Description varchar(250) )...

Selecting all child objects in Linq

This really should be easy, but I just can't work it out myself, the interface is not intuitive enough... :( Let's say I have a State table, and I want to select all Counties from multiple States. In SQL that would be: select c.* from State s join County c on c.StateCode = s.StateCode where s.TimeZone = -5 -- or some other criteria...

Why is a child property getting overwritten when a Linq object is being updated?

I'm updating one object, and trying to update any child objects along with it. Basically I'm handling the OnUpdating event of a LinqDataSource. In the DataContext class I have the ObjectUpdate function (where right now I've just got a breakpoint so I can see the values...) In the LinqDataSource.OnUpdating event e.NewObject.Child i...