Giving the following code:
Animal a = new Animal { Name = "Rover", Type = "Dog" };
ctx.Animal.InsertOnSubmit(a);
Lets say the preceding code is in a method that gets called multiple times. I do not want to submit the same object twice. Would it be possible to query the DataContext using GetChangeSet() to see if this object already ex...
Hi,
How could I add a custom propery to a LINQ2SQL class. if I have 2 properties "filename" and "filepath" and I'd like to return a property such as "fullFilePath".
thank!
...
I've been looking at the following post and trying to apply it to mine but with no luck:
http://stackoverflow.com/questions/525194/linq-inner-join-vs-left-join
I have the query below that returns 0 records everytime I run it:
var tasks = from tt in d.luProjectTaskTypes
join cbt in d.CostByTasks
...
Hi,
I am new to MVC and LINQ.
I have a table with three columns (id, text1, text2). What I want to do is generate a selectList in my view which has DataValue set to table.id, and DataText set to be = text1 + ", " + text2; (i.e. join text1 and text2 with comma separation).
What do you reckon is the best way to achieve this?
Cheers,
...
I've discovered a very nasty gotcha with Linq-to-sql, and i'm not sure what the best solution is.
If you take a simple L2S Union statement, and include L2S code in one side, and constants in the other, then the constants do not get included in the SQL Union and are only projected into the output after the SQL, resulting in SQL errors ab...
I use Linq to SQL in my project. I fetch data from a SQL Stored procedure using it. It works perfectly, but I dont understand exactly how does LINQ SQL communicates with SQL server internally, where does it stores the data after fetching it? From where it gets the connection string?
Thanks in advance..
...
Hi,
I'have a table with movies, which has an integer attribute called ranking. I'd now like to retrieve the average ranking from all movies containing a certain actor.
Dim q2 = (From p In dc.Movies Where p.actlist.Contains(actor.name) Select p.ranking).Average()
This query doesn't work - Overload resolution failed because no accessi...
How to update .dbml file after making some changes in the database.
...
Given a class
[Table ( Name = "AllPlayerInfo" ) ]
public class AllPlayerInfo
{
[Column (IsPrimaryKey = true)]
public decimal Classes_ID { get; set; }
[Column (IsPrimaryKey = true)]
public decimal Member_ID { get; set; }
//...
}
I call
DataContext db2 = new DataContext ( sqlconnectstring );
Table<AllPlayerInfo> api = db...
Let's say I have a database that stores Fruit and FruitBaskets, and it's already populated with plenty of each. In my code I'm using Linq-to-Sql so that I can treat the rows of the database as instances of the OO classes Fruit and FruitBasket. Let's say that I want to create a temporary FruitBasket in code, process with it, but I do no...
I've been reading lately about disconnected DataContexts but there's a few things I don't understand. There seems to be a scenario where you'd want to use a disconnected DataContext and then a scenario where you have to use one.
Why might you want to use a disconnected DataContext? In a single machine scenario I don't think it violat...
In LINQ-to-SQL if I update an object in the context but haven't called SubmitChanges, is there a way to "undo" or abandon that update so that the changes won't get submitted when I eventually call SubmitChanges?
For example, if I've updated several objects and then decide I want to abandon the changes to one of them before submitting.
P...
I have a Desktop application that uses Linq To SQL as the DAL. It accesses a local SQL Express DB.
If I have a SQL CE DB that has the Exact same schema(table structure) can I re-use the generated dbml with just giving it a different connection string?
...
I have a couple tables that are kind of unrelated - id like to search through both of them and create a type that i can sift through later
something like this doesnt work
var results = from dog in _dataContext.Dogs
where dog.Name.Contains(search)
from catin _dataContext.Cats
...
I've been working through the book Pro ASP.NET MVC 2 Framework by Steven Sanderson. So far it's been phenominal... just when i think I know a decent amount I find a book that shows me just how little I know.
One of the things I know little about is how to use LINQtoSQL. In Steven's book, chapters 4-6 create a very nice little shopping c...
I'm looking at an example of a save method in a Products repository from Steven Sanderson's book, Pro ASP.NET MVC 2 Framework:
public void SaveProduct(Product product)
{
// if new product, attach to DataContext:
if (product.ProductID == 0)
productsTable.InsertOnSubmit(product);
else if (productsTable.GetOriginalEntit...
I have a collection of items that is populated from LINQ and I have the need to access a sibling item (a date), that will be set from the UI level. Since I do not know the date at the time the data collection is populated, I need a good way to access the date property from each of the items in the collection. Here is my class structure s...
Hi Guys,
So i'm dealing with an ASP.NET 4.0 Web Forms Application in which the DAL is built with a combination of LINQ-SQL and classic ADO.NET (for auditing transactions, and bulk updates).
I have an admin page on the site which performs an update on a bunch of records (could be thousands), and not to mention there is T-SQL triggers in...
I am trying to check for the existence of a record in a SQL table in a if statement, I was trying to use .Count() but now understand that it won't work as it will return the total amount of all records in the table.
// If the current user does not exist in the Database, then add the user
if (staffdb.Staffs.Single(s => s.Staffname == use...
Is it possible for a project using entirely LinqToSQL or Entity Framewok to suffer from SQL Injection.
I think that probably not because the SQL that the ORM generates should be sql-injection free. But I'm not sure.
...