How do I update two tables at the same time using Linq-to-SQL?
var z = from a in db.Products
join b in db.ProductSubcategories on
a.ProductSubcategoryID equals b.ProductSubcategoryID
join d in db.ProductCategories on
b.ProductCategoryID equals d.ProductCategory...
I have a pretty complex linq statement I need to access for different methods. Each of these methods may need to see the resulting data with different parameters. For one method it may be a project code, for another it may be language. The statement is pretty much the same it's just the where part which changes.
I have not been abl...
I want to add browsable attribute to some properties for entities generated by LINQ to SQL.
Is it a good idea? Since these entities are auto-generated, and when I regenerate they (the attributes I have added) might be overwritten.
...
I am working on tool to optimize linq to sql queries. Basically it intercepts the linq execution pipeline and makes some optimizations like for example removing a redundant join from a query. Of course, there is an overhead in the execution time before the query gets executed in the dbms, but then, the query should be processed faster. I...
Hi SO, I've been having problems with the rather famous "Explicit construction of entity type '##' in query is not allowed." error.
Now, for what I understand, this exists because if explicit construction of these objects were allowed, tracking changes to the database would be very complicated.
So I ask: What constitutes the explic...
Let's say I have an Order table which has a FirstSalesPersonId field and a SecondSalesPersonId field. Both of these are foreign keys that reference the SalesPerson table. For any given order, either one or two salespersons may be credited with the order. In other words, FirstSalesPersonId can never be NULL, but SecondSalesPersonId can be...
Suppose I have an automatically-generated Employee class based on the Employees table in my database.
Now suppose that I want to pass employee data to a ShowAges method that will print out name & age for a list of employees. I'll retrieve the data for a given set of employees via a linq query, which will return me a set of Employee inst...
Let's say I have a Customer table which has a PrimaryContactId field and a SecondaryContactId field. Both of these are foreign keys that reference the Contact table. For any given customer, either one or two contacts may be stored. In other words, PrimaryContactId can never be NULL, but SecondaryContactId can be NULL.
If I drop my Custo...
This is fine, it produces a left join
var q =
from c in categories
join p in products
on c equals p.Category into ps
from p in ps.DefaultIfEmpty()
select new { Category = c, ProductName = p == null ? "(No products)" : p.ProductName };
But what about if I wanted to do something like this:
...
on p.date between c.s...
HI,
Currently i have one big datacontex with 35 tables (i dragged all my DB tables to the designer). I must admit it is very comfortable cause i have ORM to my full DB and query with linq is easy and simple.
My questions are:
1. Would you consider it bad design to have one datacontext with 35 tables or should i split it to logic units?...
I am having an issue adding an item to my dataset in Linq to SQL. I am using the exact same method in other tables with no problem. I suspect I know the problem but cannot find an answer (I also suspect all i really need is the right search term for Google). Please keep in mind this is a learning project (Although it is in use in a busin...
Here I have an arbitrary IEnumerable<T>. And I'd like to page it using a generic helper function instead of writing Skip/Take pairs every time. Here is my function:
IEnumerable<T> GetPagedResults<T>(IEnumerable<T> query, int pageIndex, int pageSize)
{
return query.Skip((pageIndex - 1) * pageSize).Take(pageSize);
}
And my code is:
...
Using the following:
private BlogDataContext db = new BlogDataContext ();
article.Created = DateTime.UtcNow;
article.Modified = DateTime.UtcNow;
db.Articles.InsertOnSubmit(article);
db.SubmitChanges();
int id = article.Id;
I am wondering is this safe? Will it give me the Id of the article that the user just inserted, or will there ...
I'd like to implement MVC while using LINQ (specifically, LINQ-to-entities). The way I would do this is have the Controller generate (or call something which generates) the result-set using LINQ, then return that to the View to display the data. The problem is, if I do:
return (from o in myTable select o);
All the columns are read f...
Hi,
Depending on how I map my linq queries to my domain objects, I get the following error
The member 'member' has no supported translation to SQL.
This code causes the error:
public IQueryable<ShippingMethod> ShippingMethods {
get {
return from sm in _db.ShippingMethods
select new ShippingMethod(
...
I noticed that MVC lets you pass in LINQ to SQL objects to its views and it will autogenerate Create, Update and View Pages based on the LINQtoSQL object.
Is there anything for webforms that lets you do this kind of thing? (In would be nice if it had validators...)
...
For the last 4 years I have been working as an ASP.NET developer in a small company where all applications are built using the Smart UI anti-pattern in .NET 2.0. This means I have no experience with .NET 3.5 and things like LINQ and general concepts like repository and service layers. I realize that in order to find a new job, I need to ...
"Error 1 DBML1005: Mapping between DbType 'Xml' and Type 'System.Xml.Linq.XElement' in Column 'XML_LAYOUT' of Type 'QUEST_BLOCK' is not supported."
The above is the error am getting. What am doing is dragging a table with xml fields as columns from server explorer into a dbml file. After that when i compile i am getting the above error....
I'm still trying to get my head round how to use LINQ-to-SQL correctly, rather than just writing my own sprocs.
In the code belong a userId is passed into the method, then LINQ uses this to get all rows from the GroupTable tables matching the userId. The primary key of the GroupUser table is GroupUserId, which is a foreign key in the Gr...
I have dropped on this question: SQL query to find Missing sequence numbers. I want to achieve the same thing but with LINQ to SQL.
To recap: I have a table with ids like 1,2,4,5,10,11,12,15, [...].
I want the unused ids 3,6,7,8,9,13,14, [...].
Can we create a temporary sequence and use the same logic as in T-SQL?
I tried to create a...