entity-framework-4

Entity Framework + Multiple Threads + Lazy Load

喜夏-厌秋 提交于 2019-12-18 07:44:37
问题 I'm having issues with Entity Framework and multiple threads and I am wondering if there is a solution that keeps the ability to lazy load. From my understanding the data context is not thread safe which is why when I have multiple threads using the same data context I get various data readers error. The solution to this problem is to use a separate data context for each connection to the database and then destroy the data context. Unfortunately destroying my data context then prevents me

Entity Framework + Multiple Threads + Lazy Load

感情迁移 提交于 2019-12-18 07:44:16
问题 I'm having issues with Entity Framework and multiple threads and I am wondering if there is a solution that keeps the ability to lazy load. From my understanding the data context is not thread safe which is why when I have multiple threads using the same data context I get various data readers error. The solution to this problem is to use a separate data context for each connection to the database and then destroy the data context. Unfortunately destroying my data context then prevents me

LINQ Query - how sort and filter on eager fetch

白昼怎懂夜的黑 提交于 2019-12-18 07:17:09
问题 How do I do a eager query of a parent child relationship that: filters a on child fields sorts on both parent and child return a List or Parents with the children pre-populated If I try from p in _context.Parents.Include("children") join c in _context.childrenon p.Id equals c.ParentId where d.DeletedDate == null orderby p.Name ascending, c.Name select p Then I get the Parent object back but each Parent has NULL for children if I try from p in _context.Parents.Include("children") orderby p

Get Total Count and Page Rows in same database trip when using Entity Framework

做~自己de王妃 提交于 2019-12-18 07:10:26
问题 I am currently using the following method to get a page of customers as well as the total count. The only problem is that I am making 2 database trips - one for getting the total count and the other for getting the actual rows for the page. My question is: Can I combine the totalcount query with the actual rows query so Entity Framework sends both the queries in a single database trip? public IList GetPageOfCustomers(string name, int skipCount, int pageSize, out int totalCount) { using

Complex Type Ignored by Entity Framework Code First

半世苍凉 提交于 2019-12-18 07:05:13
问题 Building on Ladislav's answer to Entity Framework Code First and Collections of Primitive Types I'm attempting to create a wrapper type EfObservableCollection<T> around an ObservableCollection<T> that has an additional helper property to simplify persistence (certainly this solution has trade-offs, but it's seems workable for my domain). However, properties of type EfObservableCollection<T> seem to be ignored by EF. No appropriate columns are created in the database. Guessing that

How can I add constraints to an ADO.NET Entity?

╄→гoц情女王★ 提交于 2019-12-18 05:55:54
问题 I know how to mark a group of fields as primary key in ADO.NET entities but i haven't found a way to declare unique constraints or check constraints. Is this feature missing on the designer or on the framework? 回答1: Support for unique keys/constraints does not exist in ADO.NET Entities in v4.0, see the answer to "one-to-one association on a foreign key with unique constraint", where Diego B Vega says: I know for sure we haven't added support for unique keys other than primary keys in 4.0. He

New transaction is not allowed because there are other threads running in the session

白昼怎懂夜的黑 提交于 2019-12-18 05:49:13
问题 Getting "new transaction is not allowed because there are other threads running in the session". It has nothing to do with foreach loops or anything people usually have problems with in conjunction with this message. I using a EF4 with a repositoy pattern and common context open throughout the request. Something happens, can't determine exactly what, and I get this message as soon as I try to savechanges with the context, across requests, and it only dissappears once I recycle the app pool.

How to Sort WinForms DataGridView bound to EF EntityCollection<T>

僤鯓⒐⒋嵵緔 提交于 2019-12-18 05:04:29
问题 I'm trying to bind a WinForms DataGridView to an EntityCollection<T> from an EntityFramework4 object. The trouble is, I can't figure out how to get it to sort (automatically). All I'm doing is setting the BindingSource's DataSource property to the entity's collection. MyBindingSource.DataSource = CurrentItem.InvoiceNotes; I really hope there's a simple configuration I can add to this to get it to work; I really don't want to have to wrap my EF Collection in a new BindingList container. 回答1:

EF 4, how to add partial classes

南笙酒味 提交于 2019-12-18 05:00:26
问题 I needed to extend my EF partial classes, because I want to add some functionality to able to use Oracle's sequences , however I really don't know how to use this partial class thing, I made a seperate .cs file and name it as one of my auto-generated classes as follows: namespace GlassStoreDAL { public partial class CAR { private int _sequences; public int sequences { get { return _sequences; } set { _sequences = value; } } } } Now I assumed that, on my BLL - which references GlassStoreDAL -

How to force EF Code First to query the database?

时光怂恿深爱的人放手 提交于 2019-12-18 04:53:09
问题 I have a site managing a collection of rules and a separate Windows form application making file level changes based on the rules in the database. Both of these applications use the same libraries for a EF Code First DbContext, but each application is instantiating their own copy of the context. The problem is, each running version of the context is unaware of the changes made by the other version. E.g. If I change a rule on the site, the forms app still has the previous version. I'm aware I