The problem I'm having is while using Linq2Sql with inheritance after declaring a new instance of the inherited class the discriminator property is still set to its initial value, not the correct value for the sub-type. It gets the correct value after attaching it to a context and calling SubmitChanges(). There are times where I want to ...
I have a simple data model of two tables, email and recipients, email can be sent to one or more recipients
I have setup the database with the two tables, created the Linq to SQL repository, built the controllers and the strongly typed view.
This works fine when I want to select all records from the database
public IList<AllMailDetai...
As seems to be popular at the moment, if you implement a repository as simply
IQueryable<T> FetchAll<T>();
using LINQ to SQL, then the repository must set up a DataContext which remains available outside of the repository.
So my question is, How does the DataContext get Disposed?
What if an exception is generated by the code outside ...
So it appears with a simple designer change I can make the 3 tables implement the same interface without any additional coding, from here is it possible to get the rows to behave as queryable objects of the interface type without pulling the whole table down into memory and row by row cast?
each table can be treated as such:
[Table(Na...
Our team is currently working on a large project which makes heavy use of foreign key tables as they are used on our TeamMember Management Webapp.
Basically, one TeamMember can be in a Team, in an Area and a TeamArea (the latter for editing and rights management).
My main goal is focused on retrieving the data for showing these FK Fiel...
Hello Everyone,
Let's say I have two tables one called Customers and one called CustomerAddresses. Then lets say I have a Customer object which contains a property that is of the type List<Address>. This property holds a list of all the different shipping addresses a customer may have used, so it could contain 0 - n addresses in it (j...
Before you start laughing at such a simple question let me explain:
I am trying to determine how much change (percentage %) there is in an account over various indicators. This is not particularly hard. But how do you generally handle the cases where the current value is zero or the previous value is zero?
i.e.
This week: Earnings ...
LINQ to SQL - When inserting a row (and several other rows with FKs that will point to the PK on this row), is it sufficient to execute [context].[MainTable].InsertOnSubmit(row), or do I need to call it for the other rows as well?
Here's a condensed code sample (C#):
//Forgive the contrived example (off the top of my head) :)
//Main r...
This may be a bit winded because I am new to wpf. I have created a partial class for an entity in my L2S class that is primarily used for validation. It implements the onchanging and onvalidate methods. I am trying to use the MVVM pattern, and in a window/view I have set the datacontext in the xaml:
<Window.DataContext>
<vm:StartVie...
With your LINQ or Entity Framework data models... what do you use as a standard naming convention for your data models? Or do you even have a standard? Using Northwind as the example...
NorthwindDB?
NorthwindData?
NWDB?
...
I'm trying to learn LINQ to SQL and I'm able to query the database and get back an IQueryable and manipulate the objects I retrieve from that. But I've no idea how to add a new object back into the database or into the original IQueryable.
private DataContext db;
private IQueryable<ActionType> action;
public void BuildQuery(string conn...
I I have a linq-to-sql database in which I want to log some of the changes made to an entity. Right now, I'm getting the updated entities by reading the DataContext.GetChangeSet().Updates property, but that doesn't provide me with the fields from the entity that were changed.
Is there a way to know which fields were modified in an updat...
Greetings, fellow coders!
I have this table that contains categories and subcategories (actually I don't, but let's stick to a classic example):
Id ParentId Name
1 NULL A
2 1 B
3 2 C
4 3 D
5 NULL B
6 5 D
Is there a way for me to get cat...
Hi there,
can anyone help? I have an issue with linq2sql and trying to Attach (update) an entity class through a datacontext, it complains its not the original context, this is true (see code below) ... I thought it was best practices to open the datacontext and close it when not needed?
I basically have my app calling a service layer...
Hello, Im using LINQ over DataSet but just to get data from some tables, by the way Im interesting on Fill those DataTables using LINQ2SQL cause I recently discover that on some clients with less than 1GB of RAM, the machine memory is Lacking and freeze 1 or 2 seconds and there it go normal, well whatever is frustrating for the client.
...
Can someone please check out this code, i really dont understand why i got violation of unique when i try to update an record. the code used to create new record work just fine, but when i try to use it to update, it called out violation.
Controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(User user)
{
...
I'm really confused by a behaviour of LINQ I'm seeing and it's causing me a problem.
I wrote a query like:
var reportalerts = pushDB.ReportAlerts
.Select(p => new {p.Title, p.Url, p.DateStamp})
.OrderBy(p => p.DateStamp)
.Take(numResultsPerPage);
This creates ...
Hey, all!
I'm going through a big refactoring / speed tweaking of one of my larger MVC apps. It has been deployed to production for a few months now, and I was starting to get timeouts waiting for connections in the connection pool. I have tracked the issue down to the connections not getting disposed properly.
In light of that, I ha...
After dragging two tables in from one database, I switch to another and drag a table in. Now I get a message if I want to replace the connection string with the new one. I want tables from multiple databases in one DBML. Is this possible?
...
I am trying to write a generic repository that will perform basic methods on all my linq2sql classes. (getById, insert, delete, getAll)
Im not so sure on how to get this done.
Heres what I got so far... the getById method is giving me an error cause it cant relate Id attribute to 'T' class. I would appreciate some pointers on how to wr...