entity-framework-4

Entity Framework Code First callback on object instantiation

冷暖自知 提交于 2019-12-22 11:13:00
问题 This may be a far fetched question, but is it possible to have a callback fire in an entity object, whenever a new instance of it has been loaded from the database (as part of e.g. a linq query), a call to Create or similar? The purpose of such a callback would be to convey a context, or set of initialization parameters, from the enclosing business object. 回答1: DbContext definitely doesn't have it but you can try to convert it back to ObjectContext and use: var objectContext = (

Possible to use the Repository Pattern + Stored Procedures ? Should / can they return IQueryable?

霸气de小男生 提交于 2019-12-22 11:12:14
问题 I'm a big fan of using the Repository pattern to return IQueryable<T> objects. I then let my services layer determine what does what (eg. filter by XXX, order by YYY, project into ABCD, etc). But I've got some hardcore DB stuff, so I've got it all wrapped up into a Stored Procedure . Works fine. I know EF can execute stored procs .. but I'm not sure how this fits into a Repository Pattern data layer. Does anyone have any examples / suggestions ? Do i let the repository method execute the

Silverlight 4.0 + MVC 2.0 + WCF RIA Services + EF 4.0 = Load Error

六月ゝ 毕业季﹏ 提交于 2019-12-22 10:51:39
问题 I'm trying to buid a site with the following: VS 2010 (for the updated WCF RIA Services) Silverlight 4.0 (packaged with WCF RIA Services). MVC 2 EF 4.0 I am setting it up so that the public facing pages will be html from MVC, but the administration portion will be a silverlight navigation application using using WCF RIA Services for data access. When I create the silverlight application within a webforms application, it works (I am able to add a datagrid and retrieve data using EF 4.0 and WCF

Generic repository select by ID in EF4

时光毁灭记忆、已成空白 提交于 2019-12-22 10:35:35
问题 So I'm trying to create a generic select by ID method for a base repository class. In order to achieve this I'm using EF4 with POCO's. I created an interface with a getter called Id and successfully modified the T4 template in order to have a generic Id property in all the entities that returns the PK. The problem comes when I use the query. I'm implementing it like this: public virtual T GetByID(int id) { return Database.ObjectSet<T>().SingleOrDefault(entity => entity.Id == id); } And even

Testing : How to create fake object context using TypeMock for EF4 model

橙三吉。 提交于 2019-12-22 10:23:30
问题 I am using EF4 in my application and I want to make test cases for DAL methods, which generally hit the database to get data. I am using the Typemock framework for Mocking. I want to mock database call and only want to test queries. E.g.: ObjectContext.Where(u => u.code == Code) For doing this, I need to make Fake ObjectContext for EF Models and want to fill some fake data in Fake ObjectContext so that we can execute our queries (LINQ) on fake ObjectContext . Kindly suggest how can I can

Nullable database property but texbox still shows red border when content deleted

倖福魔咒の 提交于 2019-12-22 09:39:13
问题 Hi I am binding a WPF textbox to an Entity Framework property as follows: <TextBox Grid.Column="1" Grid.Row="0" Margin="5,2" Text="{Binding Path=MyEntityObject.SizeLower, Mode=TwoWay}" /> It binds fine to the property and when I change it, it saves to the DB as expected. But if I delete the content of the Textbox I get the red error border around it. I dont have any validator in place so I am guessing the texbox is complaining about the value not being nullable. But in fact this property in

EF4: how to use a generic repository pattern ?

孤者浪人 提交于 2019-12-22 09:38:25
问题 I'm trying to streamline my existing repos by using a generic repo I can subclass from. The problem is that I can't figure out how to write a few of my base class methods. I currently have: public interface IRepository<T> : IDisposable where T : class { IQueryable<T> GetAll(); T GetSingle(int id); T GetSingle(string slug); void Save(T entity); } public class HGRepository<T> : IRepository<T> where T : class { protected HGEntities _siteDB; protected IObjectSet<T> _objectSet; public HGRepository

How to avoid polymorphic behaviour in Entity Framework TPT Inheritance in order to query base type efficiently

寵の児 提交于 2019-12-22 09:13:13
问题 Overview I am using entity framework 4.3 code first with the fluent interface to setup my DbContext. I have a base Item class with other types that inherit this such as an Event , BlogPost , ForumThread , WikiPage and so on. These inherited types are mapped with what I think entity framework refers to as TPT inheritance. This works great when querying a single type like 'events' or 'blog posts' but constructs very complicated queries with horrible performance when trying to query across all

How do I map a column to a complex type in EF4 using code first CTP5? [closed]

对着背影说爱祢 提交于 2019-12-22 09:07:34
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Having bumped into the of the lack of enum property support in Entity Framework 4 I discovered this article which describes a workaround: Entity

Entity Framework - pessimistic locking

假装没事ソ 提交于 2019-12-22 08:46:45
问题 What I am trying to do is basically what NHibernate does when you do something like: var instance = session.Get<Customer>(id, LockMode.Upgrade); I need to lock the entity row in the database. Why I need that? Imagine something like a workflow instance that can be updated by multiple actors(people or processes) at the same time. The constraints I have don't allow for optimistic locking solutions. 回答1: EF doesn't have support for this. If you want to lock some record by query you must do