In Entity Framework 4, what is the difference between Lazy Loading, and using Load() method?
Edit: I have added, two 'if' statements:
Lazy Loading:
var query = from c in context.Contacts select c;
foreach ( var contact in query ) {
if ( contact.ID == 5 )
Console.WriteLine( contact.Addresses.City );
}
Load() method:
con...
When I try to create my own POCO classes I get this error. This is only when I got a list of some kind or acsosiation like in this case the Author got Books. But it works great when I use the T4. I kinda like to create my own classes because then I could add my AddBook() to it.. so I highly appreciate if anybody know why..
Schema speci...
Hi,
Can someone confirm how to change the auto-generated connection string for an entity framework application so that it is relative?
That is so it will work for anyone who downloads and installs the application. That is, currently the connection string auto-generated for me has an absolute path in it. See below for an example:
<a...
Okay, I've been struggling with this for a while now.
I have a standard MVC2 project and use EF4 to access data objects. Many of my data objects (and therefore database tables) have two common fields: UpdateUserAccountID and UpdateDate.
In each of my controllers, I am currently setting this fields manually within each controller on the...
Will there be a problem of having datacontext object in a shared variable for a website (instead of instantiating it again and again). What I mean is, is the db connection opened for ever as long as datacontext is in memory?
Will there be a performance hit if I instantiate it everytime I need.
How about the same case for context objec...
Using WCF RIA Services and entity framework 4.
I have 3 DTOs: School, State, District.
The state DTO has a District property with composition. And the School DTO has a State property with composition and a District association.
The idea, is that when we create/update a school, we also allow the user to enter the state and district (w...
EDIT: this happen only on larger scale projects with repositories. Is there anybody using EF4 with code first approach and using repositories? please advice me
Hi. Im currently working with EF4 Code First Classes. In my test project I got two classes, Author and Book (author got books). What I'm trying to do is that I HAve a AddBook in ...
joining tables on two columns is easy
from t1 in table1
join t2 in table2
on new { KEY1 = t1.TB1Key1, KEY2 = t1.TB1Key2 }
equals new { KEY1 = t2.TB2Key1, KEY2 = t2.TB2Key2 }
select new { t1 , t2}
but what if i want an OR condition?
the SQL will look something like this:
select * from table1 t1
inner join table2 t2
on t1.TB1...
Hi,
I am creating a webapp using entity framework 4. As far as I can tell from extensive googling, it is best practice to create and kill the objectcontext when it is being used, and not let it live too long. So in my datalayer, I am doing something like:
using (var context = new MyDAO())
{
MY CODE
} creating and killing the context ri...
Is Dynamic LINQ API (released with the CSharpSamples), still the way to go, or is there a different / alternative approach with .NET 4 (and EF 4)?
...
I have a many to many relationship between Contractors and SafetyCouncils. They are joined by a bridge table ContractorsSafetyCouncils which consists of ContractorId and SafetyCouncilId. These 2 columns form a composite key. This relationship is mapped correctly in EF4. The Contractor entity has the property:
public virtual ICollection<...
I wrote a few assumptions regarding Entity Framework, then a few questions (so please correct where I am wrong). I am trying to use POCOs with EF 4.
My assumptions:
Only one data context can exist for an EF diagram.
Data Contexts can refer to more than one entity.
If you have two data sources, say MS SQL server and Oracle, EF require...
Just curious as to how Skip & Take are supposed to work. I'm getting the results I want to see on the client side, but when I hook up the AnjLab SQL Profiler and look at the SQL that is being executed it looks as though it is querying for and returning the entire set of rows to the client.
Is it really returning all the rows then sortin...
Hi!
I have this applikation that is actually two applications, a webapplication and a console application. The console application is used as a scheduled task on the windows machine and is executed 3 times a day to to some recurring work. Both application uses the same Model and repository that is placed in a seperate projekt (class lib...
I have a class called Structure:
public class Structure
{
public int StructureId { get; set; }
public Structure Parent { get; set; }
}
As you can see, Structure has a parent Structure. There can be an indefinite number of structures within this hierarchy.
Is there any way, using LINQ (with Entity Framework), to get the top-mo...
For a long time, we've wanted to create a case management system where no history is ever lost. When a change is made, we want to record that change, but have the ability to go back to any point in time and see what the record looked like. I wanted to pose this question to the Stack Overflow community to see what are some ways of doing t...
What is the right way to delete all of the collection items of an EF entity? In the code below, DocumentItems is the collection of related document items for a document. This code proceedes on Clear() but fails on SaveChanges() because related items are connected to their document via FK and FK is mandatory. So I guess they somehow remai...
I have two Entity Framework objects with a one-to-many relationship:
widget(parent) and widgetNail(child)
Widget has a text column: Title
WidgetNail has a text column: Description
I would like to build a query that will return a list of Widgets that match one of two criteria:
A text string is found in the Widget title, or
The same t...
I created a db Context class and added a connection string in my web.config file as instructed in Scott Guthrie's Code First Development with Entity Framework 4. I am running it from a test method. I received several database errors running the tests, but when I finally cleaned up the classes so the test succeeded, I still had no datab...
Hi Guys,
Here's the scenario:
ASP.NET MVC2 Web Application
Entity Framework 4 (Pure POCO's, Custom Data Context)
Repository Pattern
Unit of Work Pattern
Dependency Injection
Service Layer mediating Controller -> Repository
So basically, all the cool stuff. :)
Flow of events for a basic UI operation ("Adding a Post"):
Controller c...