entity-framework-4

Can I hide my ICollection<T> fields when I have a one-to-many mapping in EF4 code-only?

一世执手 提交于 2019-12-09 12:28:30
问题 My domain classes that have one-to-many mappings generally take the following form (untested code): public Customer Customer { // Public methods. public Order AddOrder(Order order) { _orders.Add(order); } public Order GetOrder(long id) { return _orders.Where(x => x.Id).Single(); } // etc. // Private fields. private ICollection<Order> _orders = new List<Order>(); } The EF4 code-only samples I've seen expose a public ICollection when dealing with one-to-many relationships. Is there a way to

Entity Framework 4.1 Retrieving self referencing data

亡梦爱人 提交于 2019-12-09 12:01:03
问题 I am using Entity Framework 4.1 code first and ASP.NET MVC 3 and I am struggling to get my self referencing setup properly. I have a Category class. It must be self referencing to itself. A category can be a parent category when the ParentCategoryId in the table is null. If a category has a ParentCategoryId with a value then it means that it belongs to a parent category. I followed this article on Code Project. Here is my Category class: public class Category { public int Id { get; set; }

Is there a way to find all Entities that have had their relationships deleted?

為{幸葍}努か 提交于 2019-12-09 11:29:22
问题 I am trying to not have my Business Logic know the inner workings of my Data Layer and vica versa. But Entity Framework is making that hard. I can insert into a collection (in my Business Layer) without a reference to the ObjectContext: order.Containers.Add(new Container { ContainerId = containerId, Order = order }); And that saves fine when it comes time to do a SaveChanges() in the Data Layer. But to delete an item from a collection I need a reference to the ObjectContext. (I am case #1 in

Entity Framework 4.2 "The type is not attributed with EdmEntityTypeAttribute but is contained in an assembly attributed with EdmSchemaAttribute

懵懂的女人 提交于 2019-12-09 11:08:56
问题 I am receiving the following error: System.InvalidOperationException was unhandled Message=The type 'Judge' is not attributed with EdmEntityTypeAttribute but is contained in an assembly attributed with EdmSchemaAttribute. POCO entities that do not use EdmEntityTypeAttribute cannot be contained in the same assembly as non-POCO entities that use EdmEntityTypeAttribute. Source=EntityFramework StackTrace: at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type

Entity Framework and Repository Pattern (problem with IQueryable)

巧了我就是萌 提交于 2019-12-09 11:00:47
问题 I just switched from Linq 2 SQL to Entity Framework, and I'm seeing some strange behaviors in EF that I'm hoping someone can help with. I tried Googling around, but I wasn't able to find other people with this same problem. I've mocked up a scenario to explain the situation. If I work directly with an EF context, I'm able to do a select within a select. For example, this executes perfectly fine: // this is an Entity Framework context that inherits from ObjectContext var dc = new MyContext();

Entity Framework new transaction is not allowed because there are other threads running in the session, multi thread save

别等时光非礼了梦想. 提交于 2019-12-09 09:44:53
问题 I'm tryng to save on a DB the log of a multi thread processo but I'm getting the following error: new transaction is not allowed because there are other threads running in the session. in each tread I have this function: internal bool WriteTrace(IResult result, string message, byte type) { SPC_SENDING_TRACE trace = new SPC_SENDING_TRACE( message, Parent.currentLine.CD_LINE, type, Parent.currentUser.FULLNAME, Parent.guid); Context.SPC_SENDING_TRACE.AddObject(trace); if (Context.SaveChanges

How do I prevent Entity Framework from loading a FileStream column into a byte array?

女生的网名这么多〃 提交于 2019-12-09 09:37:48
问题 I am developing a file storage application, and we have incorporated the FileStream type in our database. The system is expected to support large files. One portion of the application allows for bulk uploads of multiple documents. These documents then have to be linked to other entities within the system. One page is designed to show unlinked documents, to allow a user to link the documents one at a time to entities. After doing some load testing of the upload process, we found that the

System.ArgumentException: Duplicate type name within an assembly

左心房为你撑大大i 提交于 2019-12-09 08:36:28
问题 I am working on an ASP.Net MVC 3 web application using EF 4.1. Since today, I am getting this error: System.ArgumentException: Duplicate type name within an assembly and I can't figure out what is causing it. It is happening in my repository when performing a Find: public virtual T GetById(long id) { return dbset.Find(id); } Here is the stack trace: [ArgumentException: Duplicate type name within an assembly.] System.Reflection.Emit.ModuleBuilder.CheckTypeNameConflict(String strTypeName,

Entity Framework Context in Singleton

♀尐吖头ヾ 提交于 2019-12-09 06:54:49
问题 I'm building a App that use Context of EF in Singleton Pattern like NHibernate work with Session: public class DbContextFactory { private static volatile DbContextFactory _dbContextFactory; private static readonly object SyncRoot = new Object(); public DbContext Context; public static DbContextFactory Instance { get { if (_dbContextFactory == null) { lock (SyncRoot) { if (_dbContextFactory == null) _dbContextFactory = new DbContextFactory(); } } return _dbContextFactory; } } public DbContext

Entity Framework 4: Access current datacontext in partial entity class

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 03:11:11
问题 I want to extend an EF entity in a partial class with methods and properties. I've done this quite often. But now I would need to combine data from this entity with data from other entities. I would therefore need to able to access the entities objectcontext (if attached) to make these queries. Is there a way to get the entities objectcontext from within it? Thanx! 回答1: There is no build in way to get current ObjectContext from entity. Entities based on EntityObject class and POCO proxies