entity-framework-4

Entity Framework - Programmatically add Includes to ObjectQuery

心不动则不痛 提交于 2019-12-21 21:13:17
问题 I have a Entity Framework model where I have a user which has the following relationships: User 1-* Test Each Test has the following relationships: Test 1-1 Course Test 1-* TestEvent I have a service that returns a user and at different points in my application I want to eagerly fetch various relationships. I am fetching all the relationships at present: var result = (from appUser in context.AppUsers.Include("Tests.Course") .Include("Tests.TestEvents") where appUser.Login.ToLower() ==

Data Annotations not showing for partial Entity classes in MVC 4

这一生的挚爱 提交于 2019-12-21 20:47:10
问题 I have seen dozens of explanations of how to add metadata annotations, via partial classes, to classes generated via Entity Framework, database first . Can someone tell me why these new display values are not showing in my views? Both of these are part of the same namespace as my entity framework generated classes. [MetadataType(typeof(xRef_CodesMetadata))] public partial class xRef_Codes { } public class xRef_CodesMetadata { public int CodeID { get; set; } public int CTB_ID { get; set; }

Linq To EF : How to filter using Non-Primitive types

ぐ巨炮叔叔 提交于 2019-12-21 20:37:06
问题 public class Person { public int ID { get; set; } public int Job { get; set; } public string Name { get; set; } } List<Person> personsOfInterest = GetPersonsOfInterest(); PersonEntities personEntities = new PersonEntities(); var filteredPersons = personEntities.Where(p => personsOfInterest.Any(poi => poi.Job == p.Job && poi.Name == p.Name)); The above code generates a NotSupportedException, because Linq to Entities does not support referencing non-scalar variables( Person ). how can I resolve

Entity Framework Code First One to One relationship on composite key

删除回忆录丶 提交于 2019-12-21 19:59:15
问题 Basically what I am trying to achieve is I have three tables, one parent will always have an entry in it and only one of the other two tables will be populated. The complexity that I am dealing with is that the primary key for the tables is the combination of two fields ParentTable ----------- UniqueID OwnerID [Some more fields] ChildTable1 ----------- UniqueID OwnerID [Some more fields] ChildTable2 ----------- UniqueID OwnerID [Some more fields] I was wondering if anyone has any suggestions

Entity Framework 4.0: Adding scaler property gives error (property it not mapped: 11009)?

若如初见. 提交于 2019-12-21 19:43:08
问题 I wanted to add a new property to one of my model (table). Basically its a property that doesn't exist in the database but i need to add it to my model so that the custom generation tool (self tracking entity generator) will create the the property inside the the custom generated file. I added a scaler property, its a string and called testme but it gives me the following error, Anybody know how i can fix this? Error 2538 Error 11009: Property 'testme' is not mapped. I am confused why do i

EF 4.1 Code First: Each property name in a type must be unique error on Lookup Table association

回眸只為那壹抹淺笑 提交于 2019-12-21 17:02:01
问题 This is my first attempting at creating my own EF model, and I'm finding myself stuck attempting to create a lookup table association using Code First so I can access: myProduct.Category.AltCategoryID I have setup models and mappings as I understand to be correct, but continue to get error 0019: Each property name in a type must be unique. Property name 'CategoryID' was already defined The following models are represented in my code: [Table("Product", Schema="mySchema")] public class Product

Implement IEquatable for POCO

我的梦境 提交于 2019-12-21 12:55:47
问题 I noticed that EF's DbSet.Add() is quite slow. A little googling turned up a SO answer that promises up to 180x performance gains: https://stackoverflow.com/a/7052504/141172 However, I do not understand exactly how to implement IEquatable<T> as suggested in the answer. According to MSDN, if I implement IEquatable<T> , I should also override Equals() and GetHashCode() . As with many POCO's, my objects are mutable . Before being committed to the database ( SaveChanges() ), new objects have an

Adding additional properties to an entity framework 4 code first CTP 5 entity

北慕城南 提交于 2019-12-21 09:29:47
问题 I am using ASP.NET MVC 3 and Entity Framework code first CTP 5 . I was wondering if it is possible to add additional properties that is not mapped to a table column? I haved a News class and it is defined as such: public class News : Entity { public int NewsId { get; set; } public string Title { get; set; } public string Body { get; set; } public bool Active { get; set; } } My database context class: public class MyContext : DbContext { public DbSet<News> Newses { get; set; } } In the entity

How can I modify the default code generation strategy for edmx?

萝らか妹 提交于 2019-12-21 08:53:13
问题 I want to modify the default code generation strategy, how can I do that? I simply want to modify the class name from <#=code.Escape(container)#> to Entities and change the default connection string to name=Default . (I don't want to create a template file for the project, I want to edit it so it will work globally) I've searched for .tt files, I could only find the ItemTemplates. I don't know what generates the code by default, this is the one I want to edit. Update: I still don't know how

Entity Framework 4 update and insert one function

巧了我就是萌 提交于 2019-12-21 06:38:11
问题 I'm migrating from SubSonic to EF4. In SubSonic models had a function called Save, if the key of the model was 0 an insert was done, otherwise an update. Is there a way to make a generic Save function like in SubSonic? For exmaple using an extension method? 回答1: Yes but you have to do it yourselves. Try something like this: public interface IEntity { int Id { get; set; } } ... public void SaveOrUpdate<T>(T entity) where T : IEntity { using (var context = new MyContext()) { if (entity.Id == 0)