Why can’t Entity Framework see my Stored Procedure’s column information?
Try adding this line to the beginning of your stored procedure: SET FMTONLY OFF You can remove this after you have finished importing.
Try adding this line to the beginning of your stored procedure: SET FMTONLY OFF You can remove this after you have finished importing.
The RTM version of Entity Framework 4.1 actually includes extension methods in the EntityFramework.dll file, for eager loading with lambda through the Include function. Just include the DLL in your project and you should be able to write code like: var princesses1 = context.Princesses.Include(p => p.Unicorns).ToList(); Remember to add an Import/Using statement to include the … Read more
No. The EF inheritance does not support this scenario. The best way to create a Student for an existing Person is to use a stored procedure. Please note that this is not a stored procedure that is wired up to the Student entity through mappings, but a separate one that can be called explicitly from … Read more
Ok, so because a lot of people answered this ;), I searched a little more and I found the solution for my case. The entity looks like: public class User { public int ID { get; set; } public string UserName { get; set; } public virtual ICollection<User> Friends { get; set; } } The … Read more
This is a solution which requires only a single roundtrip: var orders = Context.Orders .Select(o => new { Order = o, SubOrderBases = o.SubOrderBases.Where(s => !(s is MyOrder)), MyOrdersWithCustomers = o.SubOrderBases.OfType<MyOrder>() .Select(m => new { MyOrder = m, Customers = m.Customers }) }) .ToList() // <- query is executed here, the rest happens in memory … Read more
Important edit There is no build in support for achieving this with two ObjectContext types. Your query must always be executed against single ObjectContext. Probably the best way to go: This was interesting enough for me to try it myself. I started with very simple idea. Two EDMX files (used with POCO T4 generators), each … Read more
First an observation about Asp.net MVC project template I must say that there is a tiny misunderstanding with Visual Studio’s Asp.net MVC project template. And that is the Model folder. People not knowing MVC pattern would automatically relate this to data model and not MVC application/presentation model. This is fine for simple applications where we … Read more
As a side not building solution supporting different provides on top of the linq is way to disaster. Linq and IQueryable are leaky abstractions – each Linq provider can have its own “features” and limitations. Moreover EF itselfs adds some logic via custom extension methods for IQueryable (like Include or AsNoTracking in EFv4.1). These methods … Read more
Use the EntityFunctions.TruncateTime method: var myQuery = from p in dbContext.Trends group p by EntityFunctions.TruncateTime(p.UpdateDateTime) into g select new { k = g.Key, ud = g.Max(p => p.Amount) };
What you are looking for can be achieved by setting up an optional association between Guest and Language entities: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Guest>() .HasOptional(p => p.PreferredLanguage) .WithMany() .HasForeignKey(p => p.LanguageID); } Unit Test: using (var context = new Context()) { var language = new Language() { LanguageName = “en” }; var guest … Read more