MyDataContext context = new MyDataContext();
// do a lot of insert, deletes and updates
context.SubmitChanges();
Will all SQL genereated and executed by SubmitChanged() be covered by a transaction? How do I make sure it's covered by a transaction?
Updated:
The reason why I asking it that I having a weird bug where I suspect a trans...
I have seen an example using the entiyt framework and it sued the ApplyPropertyChanges method to update an entity. Is there an equivilent method in plain old Linq-To-SQL?
My applicaiton is an asp.net MVC app and when I run my Edit action I want to just call sometihng like:
originalObject = GetObject(id);
DataContext.ApplyPropertyChang...
I just upgraded one of my application's methods to use compiled queries (not sure if this is relevant). Now I'm getting contradicting error messages when I run the code.
This is my method:
MyClass existing = Queries.MyStaticCompiledQuery(MyRequestScopedDataContext, param1, param2).SingleOrDefault();
if (existing != null)
{
MyReque...
I'm trying to get the null coallescing operator to work with a LINQ expression in ASP.NET MVC.
Here is my expression.
<%= Html.Encode(item.Ring.Keys.Single<ProjectOne.Key>( k => k.Literal.Value == "Class" ).KeyValue) %>
Basically, it finds an instance of the "Key" class based on the given Name, the name being the title, the result be...
Using Linq to SQL, and a DDD style Domain Layer with de-coupled repositories, does anyone have any good ideas on how to implement a specification pattern without bleeding L2S concerns up into the domain layer, that is still understandable? :)
We have complex business logic surrounding the selection of a set of transaction data, and woul...
I'm mapping my Linq-To-SQL generated entities to DTOs using AutoMapper.
When I initially created the unit tests, I had specific maps (through a static configuration class) set up to convert one type of EntitySet to a generic List (and vice-versa)
Mapper.CreateMap<EntitySet<Member>, List<MemberDTO>>();
Mapper.CreateMap<List<MemberDTO>...
Hi guys,
I'm having trouble inserting a new LinqToSql object over WCF.
What I'm doing is just sending an Orders Batch to the service. Inside the batch are Orders that have already been sent previously. When I do
data.batches.InsertOnSubmit(newbatch)
I get a sql error:
"Violation of PRIMARY KEY constraint 'PK_HTOrder'. Cannot inse...
I think I've worked myself into a pretty stupid corner, here. Let me show you the schema. I've got a lot of things around it already but I've suddenly realized a big problem.
Units
- UnitId
Rings
- RingId
Keys
- RingId (FK)
- KeyId (PK)
- KeyLiteral (FK)
- KeyValue
Literals
- LiteralId
- LiteralValue
It was good for a while. Basica...
Okay so I have the sql to work this out as asked in the stackoverflow question here.
Does anyone know how to translate this to linq 2 sql? I'm guessing that the easiest way is to add a stored procedure, but I am curious to see if it can be linq-a-fied :P
select p.*
from post p join
(
select memberId, max(createdDate) as maxd
...
Hello,
I'm using asp.net mvc with linq to sql repositories and the following code is throwing an mvc System.Data.Linq.DuplicateKeyException exception on this._table.Attach(entity)
My code is something like that:
public ActionResult Edit(int id)
{
return View(_controllerRepository.GetById(id));
}
public Actio...
I have an ASP.Net MVC web app that includes a set of Forums. In order to maintain flexible security, I have chosen an access-control-list style of security.
However, this is getting to be a pretty heavy chunk of data to retrieve every time somebody views the forum index.
I am using the EnterpriseLibrary.Caching functionality to cache ...
For clarity when I mention tiers in my question, I am referring to physical tiers (i.e. different servers for presentation, application and database)
My company has a public facing website that is currently built as a typical 2 tier system (web server and database server).
Soon a project will start in which we will be re-writing the wh...
I'm having a nightmare with LINQ.
I've got a table of Projects, and each project has many InvoiceHeaders. The Invoice header had a field AmountNet - the value of the invoice.
I want to retrive, for arguments sake, all of the fields from Projects, with the count of invoice headers and the sum of AmountNet. I.e. list of my projects, ho...
Hi,
I am using LINQ2SQL in my current project. I have a quite a lot of tables ~30. When I create my DBML file I change some of the column names etc for readability.
Recently if I made a change to the table in the underlying Database I just deleted and re-added the table in the DBML file, but this is getting tedious. How can I mimic ...
Hello,
Someone recently said that I can use Linq to SQL in my application even if I am targeting the .net 2 framework. Is that true?
How does that work? How do you setup your references? Any gotchas I need to be concerned about? Is there some special way to set that up?
Thanks.
Seth
...
I'm looking at implementing some LINQ to SQL but am struggling to see how we woudl add in access control business rules such as customer a can only view their orders.
In ado.net data services, query intercptors do exactly what I am after, and can see how to check on update / insert / delete, but is there an equivalent of this:
[QueryInt...
Hello,
Not sure if this is just a bad habit, or a valid way of doing things, but for large complex report queries spanning bunches of tables, I often get my aggregate stats by summing a Case statement.
For example:
SELECT Contact.Name,
SUM(CASE WHEN Order.Type = 'Special' THEN 1 ELSE 0 END) AS SpecialOrders,
SUM(CASE WHEN Orde...
Okay I need a sanity check here...
I've compiled a query that returns an IQueryable when executed.
On what line(s) should the query actually execute against the database in the following example?
101 IQueryable<T> results = MyCompiledQuery(MyDataContext);
102 List<T> final = (from t in result
103 where t.ID > 5
104 ...
I'm trying to eager load a couple first level association with on one of my classes, but it seems to ignore one of my LoadWith directives.
dlo.LoadWith<MyClass>( mc => m.TypeRecord)
dlo.LoadWith<MyClass>( mc => m.User)
dlo.LoadWith<MyClass>( mc => m.Item)
When I execute queries that return MyClass, A query is created that joins TypeRe...
I'm prototyping my first MVC application, it's a simple forum. I've done part of the domain model and I'm trying to figure out how to do something that's pretty basic in SQL alone, but I can't figure it out in my application. Here are my Entities:
[Table(Name="Users")]
public class User
{
[Column(IsPrimaryKey=true, IsDbGenerated=t...