linq-to-sql

programmatically navigate a linq to sql result

Hi, I have the following.... var jobsApplications = ( from applications in db.applications where applications.employeeId == LogedUser.Id select new { applications.id, applications.jobId, applications.confirmationDate }); Now I want to navigate this result like foreach "something" in jobsApplications But I ...

LinqDataSource wizard table list is not refreshing after updating LinqToSql classes

I have changed my dbml file like this. I have deleted all the tables and stored procs. I added new tables and stored procs from a new database. In the code-behind, I can access the new tables and stored procs. However, in the LinqDataSource using the same dbContext when I'm trying to configure the LinqDataSource. I can see all the ol...

Dynamic LINQ API - SQL Convert Function

I'm trying to use a Dynamic LINQ Query to query a SQL database, and in the Where clause I need to evaluate an '=' condition with a field that is of type TEXT. Right now, I've got this: var result = DBCon.PcInValue .Where(String.Format("InputName = @0 and InputValue) {0} @1", f.Condition), f.Field, f.Value) .Select("new(OrderNum, ...

How to retrive distinct month/year values from a table using LINQ to SQL

In a blog engine system I need to show all Month/Year pair values which we have blog posts in (e.g. January 2009, February 2009, ...) Is it possible in LINQ to SQL? ...

SQL Server does not handle comparison of NText, Text, Xml, or Image data types

This error occurs when data binding a repeater: SQL Server does not handle comparison of NText, Text, Xml, or Image data types protected void Page_Load(object sender, EventArgs e) { topicid = Convert.ToInt32(Request.QueryString["topic".ToString()]); if (!IsPostBack) { MusicForumDataContext db = new MusicForu...

Is there a way to do a prepared statement in linq2sql using a stored proc?

Based on what I can see the answer is no, but there is always a possibility ...

Multiple class libraries in business layer, or one?

My ASP.NET application uses only 1 SQL Server 2000 database and no more than 50 tables in it. And I copied an instance of the database to run on my develop PC, so I need to switch the connections between dev and release. The problem is, I had created multiple class libraries in my business layer, and each class library has a LINQ to SQL...

Linq doesn't recognize changes in the database

Hi, I did not find something simular so i have to ask: I use linq to SQL and all was fine until i started to use Stored Procedures to update the database entries. (My Stored Proc is something like update all entries which groupid x) The Update runs fine and the values in the database change. But the DataContext ignores this changes. ...

linqtosql 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

I cannot delete a record: public static bool DeleteProject(Project project) { invoicesLINQDataContext context = new invoicesLINQDataContext(); context.Projects.Attach(project, true); context.Projects.DeleteOnSubmit(project); try { context.SubmitChanges(); ...

The type 'System.Data.Linq.Binary' is not supported in aggregation operations.

var query2 = (from p in db.posts where (p.date) == (from q in db.posts select q.date).Max() select p.date).SingleOrDefault(); id = Convert.ToInt32(query2); I'm getting this error when trying to get the max Date from posts table, is there an alternative w...

LINQ: Associations not functioning correctly for use with innerjoins

Hi there, Can anyone help, I have been using linq2sql with great success using my associations (foreign keys) to provide inner joins etc... for example this, works great, the color is stored in a table called Color which has association so i pick it up via Color.Description - Excellent. Same for StructureType its actually an associati...

How do I map a custom Value Object in Linq-to-sql?

Hi We have a Price value object, that we want to map to a decimal SQL field via Linq-to-Sql. We use Linq-to-SQL's attributes directly (that is... we don't use the Linq-to-Sql designer). I want to write something like this: [Table] public class Product: Aggregate { //... [Column] public string Name {get; set;} [Column...

String or binary data would be truncated. The statement has been terminated.

I have an insert statement before these updates: On db.sumbitchanges the error is shown. Topic top = (from t in db.Topics where t.id == id select t).SingleOrDefault(); top.lastpost = username + maxdate; Category ca = (from c in db.Categories where c.categoryid == cat select ...

LINQ: Using a pivot table in linq

Hi there, Can anyone help? I have the following structure using associations, and as you can see v.StructureType.Description works great as its a 1 to 1 association, but i need to get in my example below v.StructureGroup.StructureGroupTariffs.Tariff.Price but StructureGroupTariffs is a Pivot table to interlink the StructureGroup and Ta...

NullReferenceException when calling InsertOnSubmit in Linq to Sql.

I'm trying to insert a new object into my database using LINQ to SQL but get a NullReferenceException when I call InsertOnSubmit() in the code snippet below. I'm passing in a derived class called FileUploadAudit, and all properties on the object are set. public void Save(Audit audit) { try { using (ULNDat...

Correct Use of XML datatype in SQL Server?

I have an application that allows my users to make temporary changes to an ongoing booking. I have recenlty read about the new XML datatype in SQL server, and the corresponding SqlXml type. I am thinking of using the new type to store the previous values of the object so that I can later revert to them. Something like: Booking Table:...

Linq2Sql - Storing Linq Expressions in cleartext (linq) for future dynamic execution.

Hello everyone, I recently posted this: http://stackoverflow.com/questions/1558269/linq2sql-storing-complex-linq-queries-for-future-dynamic-execuction-raw-text It answered one question, but sent me down a different path because of the subQuery needing to reference the same table the original query already exists in. I was able to do...

Repository Pattern and Linq to sql

I 'm trying to implement user authentication and authorization using roles table, user table and a xref table having userid, roleid. For implementing generic repoistory to update role, insert role, add user, add user to role, update user, update user role, authenticate user, add user session to audit etc do i have write seperate functi...

specific VB Linq Query help

I am still new to LINQ, and I have wrestled with a query for several days and am ready to surrender to ignorance on this one. I need to: join 3 tables (on a total of 2 databases). Lets call them Table1 Table2 Table3 Table1 joins to Table2 on "org" the result joins to Table3 on "emplid" Filters (where): Table3.success = true Table3...

Linq To SQL: Why doesn't this work?

Why do I get compilation errors from the following? int[] threadIDs = { 4,5,6,7,8,9,10,11,12,13,14,15,16,17 }; CSDataContext db = new CSDataContext(); var posts = from p in db.cs_Posts, t in threadIDs where p.ThreadID == t select p.ThreadID; ...