I have a Customer table with a Primary key (int auto increment) and an Address table with a foreign key to the Customer table. I am trying to insert both rows into the database in one nice transaction.
using (DatabaseDataContext db = new DatabaseDataContext())
{
Customer newCustomer = new Customer()
{
Email = customer.Em...
I have a query like this (created by LINQ):
SELECT [t0].[Id], [t0].[CreationDate], [t0].[CreatorId]
FROM [dbo].[DataFTS]('test', 100) AS [t0]
WHERE [t0].[CreatorId] = 1
ORDER BY [t0].[RANK]
DataFTS is a full-text search table valued function. The query execution plan looks like this:
SELECT (0%) - Sort (23%) - Nested Loops (Inner Joi...
Is there a better way to do this? I tried to loop over the partsToChange collection and build up the where clause, but it ANDs them together instead of ORing them. I also don't really want to explicitly do the equality on each item in the partsToChange list.
var partsToChange = new Dictionary<string, string> {
{"0039", "Vendor A"},
...
I have a hierarchical data structure which I'm displaying in a webpage as a treeview.
I want to data to be ordered to first show nodes ordered alphabetically which have no children, then under these nodes ordered alphabetically which have children. Currently I'm ordering all nodes in one group, which means nodes with children appear nex...
Hi, I have four tables in my database and i want to join that's and return record's and show that into searchController!
My query is this:
public IQueryable PerformSearch(string query)
{
if (!string.IsNullOrEmpty(query))
{
var results = from tbl1 in context.Table1
join tbl2 in context.Table2 on tbl...
Hello all,
Situation:
I have a web application which shows errors and where you can accept those error messages. I also have a service, which checks errors from a system and sets the error messages in the database.
When I accept an error in the web application, i would like the service to know which error message has been accepted, so t...
In C# ASP.NET MVC application I use Link to SQL to provide data for my application. I have got simple database schema like this:
In my controller class I reference this data context called Model (as you can see on the right side of picture in properties) like this:
private Model model = new Model();
I've got a table (List) of Series...
I've been doing some searching on the internet, but I can't seem to find the awnser. What exceptions can a DataContext throw? Or to be more specific, what exceptions does the DataContext.SubmitChanges() method throw?
EDIT
For reference, here a List of possible known exceptions that could be thrown by the L2S DataContext:
SqlException ...
I am trying to construct a navigation menu using a Categories table from my db.
I have a similar layout as below in Categories table.
public List<Category> CategoryData = new List(new Category[] {
new Category{ CategoryId = 1, Name = "Fruit", ParentCategoryId = null},
...
I have code something like this in an IRepository implementation in Linq to Sql:
var newlist = from h in list where h.StringProp1 == "1"
select new MyBusinessBO{
firstProp = h.StringProp1,
secondProp = h.StringProp2
};
The projection into M...
I have 3 tables: subcontracts, companies and contacts. Each table has a active_status flags which shows that the item is still active (hasn't been deleted).
Each contact has a company_id field which stores the id of the contact's company.
Each subcontract has a company_id field which stores the subcontract's company.
Each compan...
hi, i want to remove repeated record's from results but distinct don't do this for me! why???
var results = (from words in _Xplorium.Words
join wordFiles in _Xplorium.WordFiles on words.WordId equals wordFiles.WordId
join files in _Xplorium.Files on wordFiles.FileId equals files.File...
I'm using the following query syntax
from table
where
where
orderby
orderby
Where the first orderby is a date and second orderby is a date. I would assume this would work like orderby thenby but appears to be doing something else.
1 How can I do an orderby thenby using the above syntax without using extension syntax. (Got it)
2 An...
I have multiple C# projects in a Visual Studio solution right now that will all use the same SQL Server database.
What is the proper way to share LINQ-to-SQL classes between projects?
I'm considering just copying the dmbl files into each project, but I think that may be too redundant. Is there a better way to approach this?
...
I'm using LINQ to SQL and after I submit some changes I want to spawn a thread which looks through all the changes and updates our lucene index as necessary. My code looks vaguely like:
(new Thread(() => { UpdateIndex(context.GetChangeSet()); }).Start();
Sometimes though I get an InvalidOperationException, which I think is because con...
I'm running into a really annoying problem with my Linq to SQL project. When I add everything in under the web project everything goes as expected and I can tell it to use my existing connection string stored in the web.config file and the Linq code pulls directly from the ConfigurationManager.
This all turns ugly once I move the code i...
I've been using Linq to SQL for a new implementation that I've been working on. I have about 5000 lines of code and am a little ways from a solid demo. I've been pretty satisfied with Linq to SQL so far -- the tools are excellent and pretty painless and it allows you to get a DAL up and running quickly.
That said, there are some major d...
Is there an ORM out there which easily supports SQL's query notifications, so that when one client updates some data, other clients are alerted to the fact that their data is now outdated?
Ideally I'd like an ORM which manages object identity itself - that is - it refreshes already loaded objects as opposed to always creating new ones.
...
Hi Every one!
I want to fetch array of values of a single column in a table, for example, I have a table named Customer(ID,Name), and want to fetch ids of all customers. my query in LINQ is:
var ids = db.Customers.Select(c=>c.ID).ToList();
The answer of this query is correct, but I ran SQL Server Profiler, and saw the query which was...
Hi Every one!
I have a query in LINQ, I want to get MAX of Code of my table and increase it and insert new record with new Code. just like the IDENTITY feature of SQL Server, but here my Code column is char(5) where can be alphabets and numeric.
My problem is when inserting a new row, two concurrent processes get max and insert an equa...