Questions tagged [entity-framework-5]

1

votes
1

answer
1.1k

Views

EF Select MAX value that is <= 5

I can not figure out how using EF to select a DB row, based on its maximum value but wich is lower or equals 5. Here is my code, but this will select only a value, and not entire row: Prices pr = db.Prices.Where(s => s.numdays s.numdays) Thank you for your time!
CodeDemen
1

votes
2

answer
1.3k

Views

How to do computed column values in SQL Server with Entity Framework

I'm used to using identity columns and having pk's generated for me. I'm wondering, is there any way to scope an identity column or otherwise compute it to be unique within a foreign key? For example, using identity column a table might look like this: | UserId | WidgetId | w.WidgetId) + 1; EntityW...
danludwig
1

votes
1

answer
421

Views

Cannot find system.spatial.data

I just upgraded to .net 4.5rc from here and Entity Framework 5rc from here because I would like to work with the System.Data.Spatial-classes. But I cannot find the namespace in my solution. I tried searching for the classes in the object browser but without any luck. Any ideas where I can find the...
ThomasD
1

votes
1

answer
1.3k

Views

EF Power Tools Beta 2 and Visual Studio 2012 RC

The ADO.NET blog at http://blogs.msdn.com/b/adonet/archive/2012/04/09/ef-power-tools-beta-2-available.aspx says: Compatibility The Power Tools are compatible with Visual Studio 2010 and Entity Framework 4.2 or later. You can also install the Power Tools on Visual Studio 11 Beta, but you may receive...
1

votes
1

answer
499

Views

Detect If DropCreateDatabaseIfModelChanges Ran?

I am using a CodeFirst approach using EF5. I was looking at running a DropCreateDatabaseIfModelChanges to fix the database if my model changes, but there is data that needs to be repopulated when it does run. I figure that I can do an entity count to see if it was run, but I am curious if there was...
RiddlerDev
1

votes
1

answer
1.5k

Views

Cannot insert the value NULL even though column allows null

I'm testing out scaffolding with Entity Framework in Asp.Net MVC 4 (by following this article). I get it to work fine, except that even though my domain object allows null in a field and the database field allows null I get the error message: Cannot insert the value NULL into column 'IsSuccessful',...
Halvard
1

votes
1

answer
1.5k

Views

Entity Framework: Store entity property in json format

Let's say you've an entity that has a property typed as ICollection and I want to store it as varchar in SQL Server in JSON format. How to achieve this? Thank you in advance.
1

votes
1

answer
846

Views

Extracting Class Objects from Entity Framework

I have just started to investigate Microsoft's Entity Framework (EF) with a view to replacing our existing Linq2Sql data access library. Whilst following some of the sample projects I came across the 'Add Code Generation Item' (context menu on the designer surface), specifically the 'EF 5.x DbContex...
Neilski
1

votes
2

answer
208

Views

Accessing the db connection from within my code first “table” class

Is it possible to get to the current connection from inside your code first 'table' class? I'm trying to write a MVC Multi Tenancy app (1 app, many db's) the easiest way i can think of is to pass the connection string (or tenant name) when creating the dbcontext (i've looked at other ways to do this...
JimmyW
1

votes
1

answer
368

Views

In EF5 is caching of compiled queries available for short lived context?

We plan to use EF5 in a WCF service which will have a short lived context. Is the cache for the compiled queries emptied when I dispose the object context?
Mathias F
1

votes
1

answer
1.2k

Views

MVC3 Scaffolding will not generate dropdowns in views where foreign keys exist

This is driving me crazy, and I have studied the related posts on StackOverflow. Basically I have 2 tables, Album and Genre with the former having a foreign key to Genre. I have modelled this using Model First in EF5, and generated the context and class files using MS's T4 generator. Thus my Domains...
EdB
1

votes
1

answer
3.8k

Views

Can an MVC 4.5 template be installed into Visual Studio 2010?

All the demos and documentation I've seen online about Entity Framework 5 have been using Visual Studio 2012. Is there any way to use Entity Framework 5 from Visual Studio 2010? If so, do I need to use MVC4.5 or can I use an MVC4 project template still?
Jez
1

votes
1

answer
501

Views

Automatically delete orphaned childs: Childs will not be deleted for the second Commit

Further to question Can EF automatically delete data that is orphaned, where the parent is not deleted? I checked the solution, as @Ladislav suggested here https://stackoverflow.com/a/10838228/54801 Unfortunately I noticed that the solution works partially. If we take the following code: for (int k...
ari
1

votes
1

answer
2.3k

Views

Entity Framework 5 WARNING when working with a non-local workspace

I am getting the following WARNING from the emdx designer when working with my code from a shared workspace instead of the workspace being local on my own box. We need to work from a workspace off of our box. How can I resolve the issue where it won't give me that warning? Warning 1 The path '\bhg...
sagesky36
1

votes
1

answer
511

Views

How can I perform additional DB initialization when using EF (5) Code First Migrations

I'm moving my ef-code-first application to the code-first-migrations model, and switching my database initializer from DropCreateDatabaseIfModelChanges to MigrateDatabaseToLatestVersion. In my original initializer, I was creating some user-defined functions, etc. and making changes to the database c...
Gary McGill
1

votes
1

answer
2.5k

Views

Explicitly invoking DatabaseInitializer

I have a DbContext in an assembly that is shared between two service projects. I have both projects set to start for debugging in Visual Studio. This creates a race condition where the DatabaseInitializer in each service tries to update the database on startup. To prevent this, I modified my DbConte...
luksan
1

votes
1

answer
1.3k

Views

Entity Framework type case generic in predicate

I am working on updating to a more manageable repository pattern in my MVC 4 project that uses Entity Framework code first. I've integrated a generic base repository class that will do basic CRUD operations so I don't have to implement these in each repository I create. I have ran into an issue wher...
DSlagle
1

votes
1

answer
54

Views

How does one validate a partial record when using EF/Data Annotations?

I am updating a record over multiple forms/pages like a wizard. I need to save after each form to the database. However this is only a partial record. The EF POCO model has all data annotations for all the properties(Fields), so I suspect when I save this partial record I will get an error. So I am...
EdB
1

votes
1

answer
438

Views

Database Generated by EF5 Not Creating Join Table When There are Multiple Relationships

I have a User and an Organization class. They look like this public class User { public int UserId { get; set; } public string UserName { get; set; } public string Email { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public virtual ICollection Organizations...
pnewhook
1

votes
2

answer
2.6k

Views

Moving EF 5 Database first Poco classes to separate project vs2012 EF5

I've seen several answers on this question on how to one can move the model.tt (which contains the POCO entity classes ) file to a separate project in Vs2010 This doesn't seem to work in EF5 and it seems like the reason is that the model.tt file is a subitem of the edmx file. How can I achieve the...
Mixitrixi
1

votes
1

answer
1.5k

Views

Entity Framework 5 RTM Code First enum support broken: enums in other namespaces

This is about Entity Framework 5 RTM Code First. When I map an entity having an existing enum I get this error: No corresponding object layer type could be found for the conceptual type '[FULL ENUM TYPE NAME]' Actually it looks for the whole enum in the same namespace of the DbContext. Some other q...
Matías Fidemraizer
1

votes
1

answer
789

Views

VS 2012 EF 5 using .net 4 and database first Layered applications concepts

I upgraded from VS2005 to VS2012 specifically to code in .Net 4,.Net 4.5, and use EF5. I am new to EF. I have Julie's EF book but it talks mainly about EF4 and POCO and it has me confused trying to implement EF5. My hosting only allows me to run .Net 4 currently. I am trying to use EF5 on a new da...
James Perkins
1

votes
2

answer
809

Views

How does EF Code-First migration tool figure out which changes were made to the model?

I'm learning migrations and I'm curious how migration tool figures out which changes to our model were made after the last migration was created. For example, assume we created a migration M1 and apply it by issuing command Update-Database. After applying M1, if we add a new property P to a class C...
carewithl
1

votes
1

answer
94

Views

How can I add an filter attribute to every virtual properties in EF generated entity class?

I want to add a filter attribute to every virtual properties in Entity Framework auto generated entity class, how can I do this?
Ichiro Satoshi
1

votes
1

answer
48

Views

Entities Not Being Reused

I've got a new ASP.NET MVC 4 application that I'm starting to play around with. I've used Entity-Framework in the past, but this is my first experience with Code First. The trouble I'm having is that when a new PLAYER is added, a new record in the POSITIONS is also added, even though there's already...
Nick Heidke
1

votes
1

answer
564

Views

EntityFramework connection string error in windows form designer

I am facing a problem in a windows forms application (.net 4.0) using entity framework 5. I have a DbContext instance as a class field in a form like this: protected MascoteAquariumEF model = new MascoteAquariumEF('name=MascoteAquariumEF'); here is my connection string: And in the designer I am seei...
Andrey
1

votes
1

answer
541

Views

Composite keys problems to execute Find()

The number of primary key values passed must match number of primary key values defined on the entity. Parameter name: keyValues public TEntity Find(int id) { return _context.Set().Find(id); } Possible? I know have others ways for that, but I am interesting if is possible to use find on this table.
Lucas Rodrigues Sena
1

votes
2

answer
180

Views

Is there a way to get an object from the context if I only have the entitysetname and the value of a unique property?

I am trying to write a synchronisation procedure. I have a log table of my changes to the local database and want to apply them to a remote database. For each log entry I need to find the corresponding record in the remote database, given that I know the entityset name and the value of a unique fiel...
Kirsten Greed
1

votes
2

answer
870

Views

EF5 error: Cascading foreign key FK_… where the referencing column X is an identity column. Could not create constraint

I'm working on an Entity Framework 5 Code First project. Right now I'm gettcannot be createding the error: 'Cascading foreign key 'FK_dbo.DriverLicense_dbo.Person_PersonId' where the referencing column 'DriverLicense.PersonId' is an identity column.\r\nCould not create constraint These are my entiti...
polonskyg
1

votes
1

answer
214

Views

EF 5.0 Lookup Table Design Restricting Cascade Delete

EF 5.0 Code First, SQL2012 localdb I'm dveloping an application that has many lookup tables bound to comboboxes for input. When the db is built EF finds all of the relationships and adds foreign keys where appropriate. So now, as example, I have a table with a number of fields mapped to lookup tab...
user1626137
1

votes
2

answer
655

Views

Entity Framework 5 won't insert self referencing many to many relationship

I can't figure out why this configuration won't generate an insert statement to the db. I'm checking via SQL Profiler. Here is my model via Visio: Here is my edmx (this is database first). The circle shows the self referencing relationship back to GeoBoundary. Here is my code: public void UpdateAsso...
Chris
1

votes
2

answer
808

Views

How can I manage timezone differences between client and server in Silverlight?

I have SL 5 app with a form which has a field for Date. I set the default date for this field in code like: MyDate = System.DateTime.Today; Or MyDate = System.DateTime.Now.Date; then submit the data with WCF Ria Service to save the data into database. Problem is: if time zone on user client comp...
KentZhou
1

votes
2

answer
337

Views

Are “either-or” fields possible using EF, or must I use check constraints?

I am using MVC4, EF5 and SQL Server 2012 Express LocalDB‎. The Customer domain model has Phone and Email fields. Either can be null, but, at least one must be populated. I make sure of this using FluentValidation on both the client and server sides. But, when I need to persist the model, I run int...
Bobby B
1

votes
1

answer
354

Views

Entity Framework 5 - Mapping Enums - Server Error in '/' Application. The specified type member 'xxx' is not supported in LINQ to Entities

I have been having problems with enums not mapping in Entity Framework 5 (which supports enums). When I call results.Where(r => r.Category = LogEntry.LogCategory.ERROR) where results is an IQueryable I get the Specified type member LogCategory is not supported in LINQ to Entities. When I run migrati...
mancmanomyst
1

votes
1

answer
74

Views

EF 5.0 Code First mapping issues between 3 entities

I've got 2 entities: public class School { public int Id { get; set; } ... public virtual ICollection Seminars { get; set; } } public class Seminar { public int Id { get; set; } ... public virtual ICollection Schools { get; set; } public virtual ICollection Prices { get; set; } // wrong?? } public c...
skrkvv
1

votes
1

answer
810

Views

Exception performing partial update in EF 5 using context.Entry()

I am attempting to perform an update on only fields that have changed utilising the DbContext Entry() method as discussed on StackOverflow here: When I perform this on my Name and StartDate field everything runs perfectly, my SQL UPDATE statement includes only the Name and StartDate in the update pr...
GONeale
1

votes
1

answer
336

Views

DbContext Generic Method to Find Key Members

Is there a way to find Key Members of an entity (TEntity) when using CodeFirst (DbContext) on a generic context similar to ObjectContext? I can see how it's done using ObjectContext here.
imesh
1

votes
1

answer
3.5k

Views

Cannot resolve Oracle connection with Entity Framework tool

I'm trying to learn and implement Entity FW in my project (Using Oracle 11g). I'm trying to connect to my project using ODP.NET data source and getting the next error: 'ORA:12154:TNS: Could not resolve the connect identifier specified' I looked into stuckoverflow and see that the say to see if the P...
SigmaOmega
1

votes
2

answer
4.5k

Views

Failed to find or load the registered .Net Framework Data Provider. - ASP.NET MVC 4 + Entity Framework

I getting error on server while running 'Failed to find or load the registered .Net Framework Data Provider.'. I have Sql Compact 4 database included to ASP.NET MVC 4 + Entity Framework, uploading on godaddy server... web.config is following Web.Config [/xml]
Arvind Vishwakarma
1

votes
1

answer
326

Views

Entity Framework 5 installation verification

I have an ASP.NET MVC 3 project using .NET framework 4.0 and LINQ to SQL. Because I have serious problems of performance with some queries the first time they are executed I decided to use Entity Framework 5 in order to take advantage of the new LINQ auto compiled feature. Now I have installed VS 20...
Jero Lopez

View additional questions