linq-to-sql

LINQ to SQL as databinding source for WPF Treeview

I wonder if someone could provide a simple example of the following. (preferably in VB.Net): I have an SQL database with related tables and I am successfully using LINQ to SQL in other areas of my application, but am a little stuck with the Heirarchical Treeview. I would simply like to use a LINQ query from the database as a source fo...

LINQ2SQL: Cannot convert IQueryable<> to IOrderedQueryable error

I have the following LINQ code: var posts = (from p in db.Posts .Include("Site") .Include("PostStatus") where p.Public == false orderby p.PublicationTime select p); if (!chkShowIgnored.Checked) { posts = posts.Where(p => p.PostStatus.Id != 90); } That last line (the extra where) is giving me the error: Cannot im...

"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."

Hi, All When I run following code: public ActionResult Complete() { try { VeriTabanDataContext db = new VeriTabanDataContext(); db.Persons.InsertOnSubmit(_person); db.SubmitChanges(); return View(_person); } catch (E...

Which is the best for a 3-tier architecture; Linq to SQL or Nhibernate?

Which is the best solution for 3-tier arch. Linq to SQL or Nhibernate? Specifically, I will upgrade a system in 2-tier architecture to 3-tier architecture? Edit: And where can I find good tutorials or videos for both? ...

Determine the number of Linq-To-Sql queries used in processing an ASP.NET MVC URL?

I'm using Linq To Sql now, and how can I know how many queries was used to show the current page? thank you very much ...

LINQ2SQL: Update an entity field that has a reference to another entity

I have the following situation in LINQ: I have an object (a blog "Post") that has a "Status" field which can take on different values, and there's a table listing all these values (this table just has Id, Desc). Now, since the relationship between both tables is created, in the Model, Post.Status is not an int, but an instance of "PostSt...

Linq to Sql supports my string query but not in a property. Can I make it?

I have a class with a title in it. I have a property that returns that title adjusted a bit. If I do Linq to Sql queries off the adjusted title property I get the "not supported" exception. If I do the same thing the property does directly in the linq query it works. Any ideas on how I can make the property work in Linq to Sql? Here is ...

How can we assume a bool Property on a Generic<T> class , where T is a auto generated LINQ2SQL class

I am doing a CRUD operation on Database generated class(using LINQ2SQL) in my WPF application. All of my DB tables have IsDelete property exists. So I want to define an abstract/interface class to do the SoftDelete(). My question here is, how can I define my Generic class in such a way as to access T.IsDelete = true ? or in code I want t...

LINQ-TO-SQL: add data to database without schemes and sqlmetal?

Hello. Right now i'm exploring LINQ-to-SQL using Visual Studio 2010 beta. I'm trying to understood the bascis for now, without magics light code auto generated from schemes and from sqlmetal. I have tried the following code: public class Database : DataContext { public Database( string s ) : base( s ) {} public Table< DUser ...

Linq Query - how can you improve the following query?

Hi guys, I have a Linq To Sql query in my asp.net website. This query works too Slow and im sure that it can be improved. Can anyone help me ReWrite this query? I assume using "join" would make it quicker but couldn't get it right. :( Here is the query: (input params : INT_GENDER ) var users = from u in db.Users wher...

How do I code this SQL query in Linq-To-SQL?

I'm new to MVC and its going well but struggling a bit with the back to front SQL etc select * from aspnet_Users where Active = 1 and UserId in (select UserId from aspnet_UsersInRoles,aspnet_Roles where aspnet_Roles.RoleId = aspnet_UsersInRoles.RoleId and aspnet_Roles.RoleName = 'Auth Level 1') Tables and fields are: aspnet_Users (U...

Which is beneficial for start up; Linq to SQL or Nhibernate?

I want to learn ORM and I wonder which is beneficial for start up; Linq to SQL or Nhibernate. considering time,adaptation... etc ...

inheritance in linq to sql

Hi Experts, In LINQ to SQL, Can we inherit our entity classes from some other class or interface. I have some common work for all my entities, which I want to code at some common place and call it once. Regards Parminder ...

Linq2Sql FROM XSD

I have a scenario where I define the XSD first, then generate the cs files from these XSD (using xsd.exe). I need to take this 2 steps furthur by generating the dbml from these and then calling CreateDatabase() on that dbml). So the question is, does anyone have an idea how to create dbml from either an XSD or a cs file? Thanks Ash ...

Filtering database records by xml column content using linq-to-sql and xlinq

Hi I need to select rows from database table using filtering by xml-type column. table looks like (short version) id dbfield int xmlfield xml and i'm filtering it in this way IQueryable<Data.entity> q = from u in datacontex.entities select u; if (val1.HasValue) q = q.Where( x => x.dbfield > val1.value) if (val2.HasValue) q = ...

Linq DBML Mapping a Table With A Primary Key That Spans 2 Columns

I have three tables: Login, LoginRoles and Roles. Login joins to LoginRoles and LoginRoles joins to Roles. LoginRoles is a many-to-many table, and I want to constrain the columns as being unique TOGETHER. LoginRoles: MemberId (int), RoleId(int) This is similar to the aspnet_UsersInRoles table in the default membership database: Tabl...

How do I extract this LinqToSql data into a POCO object?

Hi folks, with my Repository classes, I use LinqToSql to retrieve the data from the repository (eg. Sql Server 2008, in my example). I place the result data into a POCO object. Works great :) Now, if my POCO object has a child property, (which is another POCO object or an IList), i'm trying to figure out a way to populate that data. I'...

linq operator like * (asterisk) in sql

I want to select all the fields of one table, and only specifics fields of a second table. Are there any way to do it like with table.* in SQL? var things = from t in db.table1 from t2 in db.table2 where ...Join Clause... select new { t.*,t2.onefield} obviously this code don't work, but I thi...

Creating association with custom field in Linq2Sql

Scenario Table A: field_1 (with leading 0's, Ex. 125) Table B: field_1 (no leading 0's, Ex. 000125) What is the best way to setup my model in L2S so that I can have an association b/t the 2 tables by the "field_1" column? I basically need a way to create a custom property (or whole seperate entity) that I can perform a simple...

Linq To Sql optional Column

My problem in short: I need a functionality to have optional columns in a linq to sql definition. So that linq to sql normally ignores this column within selects and updates etc. But if a select contains a value for this column it should use this value. Long version: The Scenario I've the following tables: If Field.FieldViews.Coun...