linq-to-sql

"Attach or Add an entity that is not new...loaded from another DataContext. This is not supported." Problem on insert of linker object.

Similar error as other questions, but not quite the same, I am not trying to attach anything. What I am trying to do is insert a new row into a linking table, specifically UserAccomplishment. Relations are set in LINQ to User and Accomplishment Tables. I have a generic insert function: Public Function insertRow(ByVal entity As Impleme...

Client-side Replication for SQL Server?

I'd like to have some degree of fault tolerance / redundancy with my SQL Server Express database. I know that if I upgrade to a pricier version of SQL Server, I can get "Replication" built in. But I'm wondering if anyone has experience in managing replication on the client side. As in, from my application: Every time I need to creat...

Passing filtering functions to Where() in LINQ-to-SQL

I'm trying to write a set of filtering functions that can be chained together to progressively filter a data set. What's tricky about this is that I want to be able to define the filters in a different context from that in which they'll be used. I've gotten as far as being able to pass a very basic function to the Where() clause in a LIN...

The data types text and nvarchar are incompatible in the equal to operator

Hi there. this is my code ProductController.cs public ActionResult Details(string id) { product productx = productDB.products.Single(pr => pr.Product1 == id); return View(productx); } Details.aspx <td> <%-- : Html.ActionLink("Edit", "Edit", new { id=item.Id }) % --> <%: Html.ActionLink("Details", "Deta...

Is Entity Framework worth moving to for a new small app?

Hi Is Entity Framework worth moving to for a new small app? About 10 tables and a WinForms app. ie the alternative being DataTables/DataRows or Linq-to-SQL ...

Why LINQ 2 sql gives better perfomance?

I read in some article that LINQ to SQL gives better performance when executing stored procedure than Entity framework. Any obvious reasons for it? ...

Out of memory when creating a lot of objects C#

I'm processing 1 million records in my application, which I retrieve from a MySQL database. To do so I'm using Linq to get the records and use .Skip() and .Take() to process 250 records at a time. For each retrieved record I need to create 0 to 4 Items, which I then add to the database. So the average amount of total Items that has to be...

What’s the Linq to SQL equivalent to CEILING?

How do I do this SELECT CEILING(COUNT(*) / 10) NumberOfPages FROM MyTable in Linq to SQL? ...

Linq to SQL DynamicInvoke(System.Object[])' has no supported translation to SQL.

I have a class, Users. Users has a UserId property. I have a method that looks something like this: static IQueryable<User> FilterById(this IQueryable<User> p, Func<int, bool> sel) { return p.Where(m => sel(m.UserId)); } Inevitably, when I call the function: var users = Users.FilterById(m => m > 10); I get the following except...

How to write Sql or LinqToSql for this scenario?

How to write Sql or LinqToSql for this scenario? A table has the following data: Id UserName Price Date Status 1 Mike 2 2010-4-25 0:00:00 Success 2 Mike 3 2010-4-25 0:00:00 Fail 3 Mike 2 2010-4-25 0:00:00 Success 4 Lily 5 2010-4-25 0:00:00 Success 5 Mike 1 2010-4-25 0:00:00 Fai...

How do I switch the table that is queried with linq-to-sql

We have two tables with the same set of columns; depending on the “type” of object the value is stored in one of the two tables. I wish to use common code to access these two tables. If I was using “raw sql” I could just use String.Format() to change the table name. (Likewise for updates etc) The two separate tables are needed a...

Association in Linq To SQL showing as an EntitySet<>, why?

I am having a lot of trouble coming up with the Linq equivalent of this legacy stored procedure. The biggest hurdle is it doesn't seem to want to let me add a second 'clause' on the join with tblAddress. I am getting a Cannot resolve method... error. that tblBusiness.tblAddress is seen as an EntitySet<tblAddress> See bottom for curre...

Connection Pool error LINQ to SQL

Guys, In Our project I have used LINQ to SQL for every kind of database interaction. Now from what I know , When I create and use DataContext object : it opens the connection , crates a transaction , perform the query and closes the connection. Every now and then we are getting Connection pool error on our services and Server. " The ...

Linq to SQL inheritance and Table per Class - approach needed for multiple roles

I am using L2S and an inheritance model for mapping Persons against certain roles. Guy Burstein's excellent blog post explains how to accomplish this: http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/10/01/linq-to-sql-inheritance.aspx However, I have a specific case where a Person has multiple roles. For example 'Jane Doe' is ...

What does DataContext.GetTable<TEntry> do?

Consider I have a DataContext db, and there is an Entity class User. So when System.Data.Linq.Table<User> table = db.GetTable<User>(); is called for the first time, does it pull the data from the database immediately, does it use deferred execution, or were the data already loaded from database when db was initialized? ...

Should Save/Update repository methods use a new data context?

Should each save/update method in a LINQ-to-SQL repository be wrapped in a new data context? Consider the SavePage method in my partial SqlPageRepository: public class SqlPageRepository : IPageRepository { private DB _db; public SqlPageRepository(DB db) // I use IoC { _db = db; } public IQueryable<Page> Ge...

Automatically generate buddy classes from model in C#

I use Linq to Sql (although this is equally applicable in Entity Framework) for my models, and I'm finding myself creating buddy classes for my models all the time. I find this time consuming and repetitive. Is there an easy way to automatically generate these buddy classes based on the models? Perhaps a visual studio macro? An examp...

How to get List of results from list of ID values with LINQ to SQL?

I have a list of ID values: List<int> MyIDs { get; set; } I'd like to pass this list to an interface to my repository and have it return a List that match the ID values I pass in. List<MyType> myTypes = new List<MyType>(); IMyRepository myRepos = new SqlMyRepository(); myTypes = myRepos.GetMyTypes(this.MyIDs); Currently, GetMyTyp...

Applying Domain Model on top of Linq2Sql entities

I am trying to practice the model first approach and I am putting together a domain model. My requirement is pretty simple: UserSession can have multiple ShoppingCartItems. I should start off by saying that I am going to apply the domain model interfaces to Linq2Sql generated entities (using partial classes). My requirement translates i...

Linq to Sql saying that item by 'Customer' already exists. Choose a different name.

I have been going round and round with a linq to sql file while using svn for quite some time. The latest is that my dbml file shows as having an error which states that An item named "Customer" already exists. Please choose a different name. And then it repeats that again. In fact, it says it for almost every object. What...