entity-framework-4

How to use the poco entity generator

I'm using VS2010, and I've download the C# POCO Entity Generator installed it, now I want to use it. I can't read the toturial and I can't find any other good toturials, so I've had a go myself - I have created a model and then I'm creating new POCO Entity, but I got the bellow error: Error 1 Running transformation: System.Reflection.T...

Do Linq to Entities queries *always* hit the database?

My understanding of the Entity Framework is that if it can answer a query from its cache, it will. My simple testing, however, shows repeated queries hit the database even though they were previously answered positively: var u1 = context.Users.SingleOrDefault(u => u.Id == 1); var u2 = context.Users.SingleOrDefault(u => u.Id == 1); Th...

Changed property value when selecting in EF4

I need to change the value of a property when I query the database using EF4. I have a company code that gets returned and I need to translate it to another company code, if needed. So, there is a stored procedure that is used to do this currently. Here's the old select statement. SELECT companyName, TranslateCompanyCode(companyCode) as...

EF4 - Map 1 Table to 2 Objects

In my previous question, I asked how I would design the database schema where 1 table (Comments) would reference 2 tables (Question and Answer). I was given the response to use one table for Question and Answer (SO uses Posts). Now I am in Entity Framework 4. How can I set it up so that this one table (Posts) maps to 2 objects (Ques...

Code First CTP: Multiple PKs or FKs

Hello, In some instances, we may have PK/FK references duplicated, so entity A and entity B are in a PK/FK relationship, but 3 times. So entity A would have 3 FK collections and entity B would have 3 entity references. How does that work with the code-first template? Do you follow the naming convention of Entity Framework model/datab...

Is it possible to use lazy-loading function in EntityFramework4 in conjunction with WCF?

my application is using WPF for UI, WCF for WebService, EF4 for DataAccess. I read some materials from internet and msdn that EF4 has self-tracking function using custom T4 template even if using together with WCF for ntier. Does this mean that lazy loading function is still possible with WCF? Thanks ...

Where is the best place to put validation logic given this application design?

Consider an ASP.NET MVC 2 web application project that uses EF4 POCO entities and the repository pattern to store information in a SQL Server database. So far there are 3 projects, 4 if you count the database: 1.) Domain.dll, has no dependencies, exposes POCO's and repository interfaces. 2.) Storage.dll, depends on Domain, implements ...

MVC2, EF4, layers, STE and validation

I see that most of people interested in EF4 are MVC developers. So; for a MVC2 medium application that implements DDD (Interfaces, Repositories, Services, Entities and IoC): Do you recomend separating the different concerns in layers and using Self Tracking Entities? (here I know that ObjectChangeTracker is not being used but I don't f...

Datatype convert problem

in DB, a SP return a bit result. like: declare @temp bit; --...... return @temp; in EF, impport this SP as function and return scarlars Boolean. in domain service call this function as: public bool CallSP() { var result = this.ObjectContext.MySp(); return (bool)result; } then get error as: Cannot convert type 'System.Data.O...

How to auto-update the Modified property on a Entity in Entity Framework 4 when saving?

Im using EF4 in VS2010, POCO's and the model-first approach. My entity has the following properties: Id:Guid, Name:String, Created:DateTime, Modified:DateTime, Revision:Int32. I create my entity, set the name and save it to the database using the EF4-context. This should set Id to a new Guid (works with Identity-SGP), Created set to no...

How to call function imported from SP?

With EF and WCF Ria Service, domaincontext object provides following generaic method to load entity colloection: DomainContext.Load<T> Here T must be type of Entity, not allow primitive type like bool, Boolean,... If I have SP function call return scarlars result, what't generic method to call those function at client side? ...

How to Create a Enitity Framework Project?

OK, so I feel dumb for asking this... but I am stumped. I can't seem to create a project/unit for using the ADO.NET Entity Framework. I looked for a project type that looked like it would match, but no go (closest I could find was ASP.NET Dynamic Data Entities Web Application). I also tried to just add a unit (like you do for Linq-to...

Entity Framework 4 - AddObject vs Attach

Hi All, I have been working with Entity Framework 4 recently, and am slightly confused as to when to use ObjectSet.Attach, and ObjectSet.AddObject. From my understanding: Use "Attach" when an Entity already exists in the system Use "AddObject" when creating a brand new Entity So, if i'm creating a new Person, i do this. var ctx = ...

Error 2062: no mapping between entity set and association set

Are entities required to be mapped to a table or can they map to a stored procedure? I have an entity that does not map to any specific table, instead it maps to a stored procedure. I am getting the following error: Schema specified is not valid. Errors: Model.msl(6,6) : error 2062: No mapping specified for instances of the ...

EF 4.0 POCO magic doesn't work-- No changes detected.

I can't seem to update my database from disconnected poco objects. In this example, I fetch an ApplicationUser object, update varchar(100) field SSOID, but no changes take effect. Even when I refetch the object in the save method, nothing gets sent to the db. If I try to call ApplyCurrentValues, it throws An object with a key that m...

Entity Designer Database Generation Power Pack generates datetime and not datetime2 for ProviderManifestToken = 2008

Im having trouble with the DDL-generation from EDMX using the "Entity Designer Database Generation Power Pack" add-on. It generates datetime-columns instead on datetime2 even though ProviderManifestToken is set to 2008. Can it be fixed? I don't want to do this manually all the time because Im using the model-first-approach... ...

Poco class inherit entityobject

I have a t4 template wich generates my poco classes. Everything is working fine. Now, i want to inherit those classes from EntityObject (i want to know about EntityState sometimes) but when i do this, the relationships are always returning null (lazy loading not working). Any suggestions ? Here is a simple model public partial cla...

How can I execute an Oracle function from within a LINQ expression in Entity Framework 4?

I am using Visual Studio 2010, C#, Entity Framework 4 and Oracle 10g. I need to be able to return the result of a database function as a scalar property of an anonymous type. My Oracle schema has two tables, PARENT and CHILD, and a function FNC_ADD. I have created an entity model using the Visual Studio ADO.NET Entity Data Model templ...

Persisting a Single Entity and it's Related Entities

Hi all, I have question about Entity Framework. I did a search here but could not find a very good solution. I maybe be using EF in a strange way that is not typical. Basically I declare a context on the start of my appliction and load the data I need. I'm using MVVM design patern for a C# WPF desktop application with a SQLite backend...

Execute a SQL stored procedure before every query generated by EntityFramework

I need to execute a SQL stored procedure every time before I query my ObjectContext. What I want to achieve is setting the CONTEXT_INFO to a value which will be later on used with most of my queries. Has anyone done that? Is that possible? [EDIT] Currently I'm achieving this by opening the connection and executing the stored procedure...