Adding EF4 is a null clause on the where clause

I have the following linq query: var fileDocuments = ( from doc in fileUploads from invoice in ( from inv in _dbContext.SupplierInvoiceHeaders where inv.InvoiceDocumentId == doc.ID || inv.JobSheetInvoiceId == doc.ID select inv ).DefaultIfEmpty() join

Self-referencing 1 to many relationships

I have the following entity: public class TravelCoverageType { public int Code { get; set; } public virtual TravelCoverageType PreventedBy { get; set; } public ICollection<TravelCoverageType> PreventCoverages { get; set;} ... } Each TravelCoverageTy

Zero exception rejected by LINQ to EF

This line of code is throwing an exception: Dim z = (From r In t Where (DateTime.ParseExact(r.appt_date, "yyyyMMdd", CultureInfo.CurrentCulture).Date.Month _ = myDate.Date.Month) And _ (DateTime.ParseExact(r.appt_date, "yyyyMMdd", Cult

Avoid writing the connection string in the code

I already finished my first c# application which manages some tables on a sql server 2005,but I want to modify it so that it could read the connection string from a text file . By doing that I can move my application to another PC by only changing th

Entity Framework and a connection from zero to zero (?)

I got intresting situation when two kind of dependent tables sometimes must work together. Example: When two people from different departments to bring data, one machine, the second about the engine, do not know which engine would go to which machine

Using Entity Framework

I just started using Entity Framework and it created a Context class which I can use to get all the data i need from it. But I am facing an issue on how I should organize my code, by watching the demos, the person just uses the framework and codes ev

Prioritizing fields when matching multiple fields with linq

I have a database with fields like firstname lastname street and searchfield. Anything that match the search field will be in my search subset here is the linq logic : if (!String.IsNullOrEmpty(searchString)) { folders = folders.Where(p => p.SearchFi

Entity Framework Code First Transaction

I am using Entity Framework 4 with SqlServer CE as the database. Because SqlServer CE does not support TransactionScope, so I have to resort to using BeginTransaction and RollbackTransaction method. I have two GRUD functions to delete and create rows

Automation of ConcurrencyMode set to Fix in EDMX

Majority of our tables in our models has a field called "intConcurrencyID" that we intended to use for concurrency checking. I believe the only way to enable this field for concurrency checking in a Database First environment is to set the Concu

Need a Linq query for a matching Sql query

Basicall I have three Tables Users Roles and USerRoles with Many to many Relationship. So when I import these on .edmx i get only two Entities. so i have Navigation Properties in both Entities. I have three Users and 2 Roles (admin and ReadOnly). So

Adding and removing many-to-many using the DbContext API

I am using Entity Framework and DbContext API do build my application but I am having trouble working with objects with many-to-many relations. A simplified save-method could look like this public void MyObj_Save(MyObj myobj) { DbContext.Entry(myobj)

A cycle has been detected in a LINQ expression exception

I get the error : A cycle was detected in a LINQ expression. in ToList() while trying to do the following: private IEnumerable<int> FilterIdsByClient(IEnumerable<int> entityIds) { entityIds = MyObjectContext.CreateObjectSet<TEntity>() .W

Try catching in the repository

None of the examples I have looked at for Repository Patterns include any kind of error handling. Why is this? Say for instance I have this: public virtual TItem Insert<TItem>(TItem item) where TItem:class,new() { dbContext.Set<TItem>().Add(it

Model MVC3 EF-first with POCO and ViewModels

Lots of great posts out here on this topic and I've tried to read them all. I'm a long time n-tier developer but trying to swing into action with an MVC3/EF application. I've generated POCOs via the EF POCO generator(T4). I'm also binding ViewModels

EF4 update a value for all rows in a table without selecting

I need to reset a boolean field in a specific table before I run an update. The table could have 1 million or so records and I'd prefer not to have to have to do a select before update as its taking too much time. Basically what I need in code is to

LINQ to Entities how to update a record

Okay, so I'm new to both EF and LINQ. I have figured out how to INSERT and DELETE but for some reason UPDATE seems to escape my grasp. Here is a sample of my code: EntityDB dataBase = new EntityDB(); Customer c = new Customer { Name = "Test", Ge

Conditional impatient loading?

I want to load an entity and it's children conditionally (I only want to eager load the children when the child.IsActive == true). How do I perform the following? var parent = from p in db.tblParents.Include("tblChildren") <-- where tblChildr

Context.CreateQuery & lt; T & gt; is loading everything?

I have been working away for EF4 and got a lot of stuff done and its working really nicely, the one problem I do have is: Context.CreateQuery returns correctly, but it is also loading ALL its related entities too!? Which is going to cause massive iss