entity-framework

How to change the return type when validate property changing on entity ?

With EF 4.0, for each property, EF provides following way for customized validatation on property changing: partial void OnMyNameChanged() { //..... } the return type is void. But I want to change the return type, say like bool or string. Is it possible to do it in this way? ...

How to get the original value when update entity property?

When update/modify entity property, I can put business logic in property changed event like: partial void OnMyPropertyChanged() { //.... } In this event handler, I want to know the new value and original value for MyProperty. New value can be get by this.MyProperty. How to get the original value? For example, if udpate MyProperty ...

EF4 is throwing an error "Schema specified is not valid"

I'm getting a weird EF4 "Entity Framework v4" error when I do a select on the context. There I get is: Schema specified is not valid. Errors: The relationship 'AnalyzerConfigurationModel.FK_AnalyzerMetadataParameters_AnalyzerMetadata' was not loaded because the type 'AnalyzerConfigurationModel.AnalyzerMetadataParameter' is not availab...

WinForm for creating ADO.NET Entities that have relationships with other entities

I am very new to the ADO Entity Framework, and I'm looking for the best practice. Here is the scenario: I have a database with a Person table and an Address table. Person has a foreign key referencing the primary key of Address, an auto-incrementing int. First, I've created an ADO Entity model with VS 2010, and sure enough the relat...

Missing something with Entity Framework for .NET 3.5?

Is it not possible to have EF create the necessary entities when I have two related tables linked with a FK in .NET3.5SP1? I see where the checkbox to support this is disabled but it is available in .NET4. I've got a DB that has only tables with relationships in it. I need to build a Silverlight app (SL4) that allows management of the d...

Problem with Entity Framework 4, Complex Types, StoredProcs, and temp tables

Hello, I am skinning my knees on Entity Framework 4 and running into a slight problem. I have some stored procedures that I am pulling into my EDMX. When I create complex types from these procs, EF has no problem getting the column information. Except in one place. After being puzzled for a while, I figure out it was my temporary ...

Entity Framework not populating context

I'm just starting out with some entity framework exploration, I figured it was time to see what everybody was complaining about. I am running into an issue where the entities don't seem to be returning any of the object context. I generated the model from a database with three tables which link to one another. Courses Instructors Ca...

Entity Framework Decorator Pattern

In my line of business we have Products. These products can be modified by a user by adding Modifications to them. Modifications can do things such as alter the price and alter properties of the Product. This, to me, seems to fit the Decorator pattern perfectly. Now, envision a database in which Products exist in one table and Modificat...

Entity Framework 4 "Generate Database from Model" to SQLEXPRESS mdf results in "Could not locate entry in sysdatabases for database"

I'm using Visual Studio 2010 RTM. I want to do model-first, so I started a new MVC app and added a new blank edmx. Created a few entities. No problem. Then I "Generate Database from Model", and allow the dialog to create a new database for me, which it does successfully as 'mydatabase.mdf' in the app's App_Data directory. Then I open th...

Using LIKE operator in LINQ to Entity

Hi, everybody! Currently in our project we are using Entity Framework and LINQ. We want to create a search feature where the Client fills different filters but he isn't forced to. To do this "dynamic" query in LINQ, we thought about using the Like operator, searching either for the field, or "%" to get everything if the user didn't fil...

Entity Framework query builder methods: why "it" and not lambdas?

I'm just getting started with EF and a query like the following strikes me as odd: var departmentQuery = schoolContext.Departments.Include("Courses"). OrderBy("it.Name"); Specifically, what sticks out to me is "it.Name." When I was tooling around with LINQ to SQL, pretty much every filter in a query-bui...

MSDTC and Multiple Databases with Entity Framework.

In my code I'm attempting to use a transaction using TransactionScope with Entity Framework. While in this transaction we are opening a regular SQL connection to a seperate server and database. When the conn.Open() is called we get an Error: "Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enab...

Entity Framework .. partial constructor

Hi .. I intend to extend the constructors of some of the entities in my Entity Framework (4). However how do I ensure that my constructor is run after the model has run its. i.e. I want to ensure that the the object holds the data from the database before I work on it in my constructor. ...

WPF and ADO.NET EF - not working

Hi, I'm writing a piece of code that takes the records from a sql ce 3.5 database, creates images based on the url provided and then fill the observablecollection with those Images. It looks like this: private void UserControl_Loaded(object sender, RoutedEventArgs e) { Entities db = new Entities(); ObservableCollection<Image> _...

Entitiy Framework: "Update Database from Model" instead of "Generate Database from Model"

Hey everyone, I have created a Entity Framework 4 model with Visual Studio 2010 and generated a database from it. Now I found myself adding new properties (with default values), changing documentation of columns, changing names of columns, changing types of columns several times. All tasks that do not require much "extra work" in order ...

How to get dynamic SQL result from SP in entity framework?

Suppose I have following SP to run a dynamic sql ALTER PROCEDURE [dbo].[MySP] AS BEGIN declare @sql varchar(4000) select @sql = 'select cnt = count(*) from Mytable ..... '; exec (@sql) END then in edmx, I add the sp and import function for this sp. the return type is scalars int32. then I want to use this function in code like...

what alternatives are there to traverse a hierarchy of entities

The classic exmaple of "show Bill and all the employees that report to hiM" is answered easy enough with T-SQL and a recursive CTE such as: with cte as ( select *, 0 as level from employees where username = '[email protected]' union all select employees.*, level+1 from employees join cte on employees.reportsTo = cte.id ) select * from...

WCF Data Service: 'No operations found'

I've just built an EF model over a db (Framework 3.5 sp1), and I want to create a WCF Data Service to deploy it. No problem with the entities, but now I've created a service operation like this: [WebGet] public IQueryable<person> PersonsGetAll() { return this.CurrentDataSource.persons; } and I've setted in InitializeService: conf...

Custom OData operation / customize EF model to hide join table in many-to-many relationship

I've got a data model that has two tables with a join table for a many to many relationship & creating an OData service to expose the data for CRUD ops in a Silverlight app. What I'd like to do is abstract the join table from the service. I'm not sure if the best way to do this would be in the model (using EF in .NET3.5SP1) or if I shoul...

Help creating a Windows Form for an Entity who has a reference to a different Entity.

Here is the scenario (ADO.NET Entity Framework and C#). Contact*: String name; Address addr; Address*: String street; String city; *this is not the real code, but you get the picture I am trying to create a Windows Form that appears flat to the user. In other words, the Form will have four fields (name,addr,street,city), and whe...