entity-framework-5

EF vs Nhibernate Merge Disconnected Object Graph

巧了我就是萌 提交于 2019-12-07 05:40:46
问题 I just started a new project a few weeks ago and decided to give EF Code First a try, I used NHIbernate before and i loved the idea of having an ORM out-of-the-bow from MS, and so far it's been great - until i started making complex objects. My project tiers are as follows: Azure WCF Role - to handle the DAL with EF Code First. Azure WebSite Role with MVC 4 with Knockout - to deal with the client. (I created the WCFRole for the future where we'll need access to the service from different

POCO Class in EF not working as Expected

≡放荡痞女 提交于 2019-12-07 03:37:28
问题 I have created a DataBase in SQL and created an EDMX in Visual Studio 2012. It automatically created POCO (TT) classes. Everything looks fine. Now I change the column name of a table. I update the EDMX. Opening the EDMX in XML and everything looks fine. Question 1 After I ran Custom tool in TT, I see that a new property got created additionally, e.g.: SQL table name : Student Column name : sName In my POCO Class public int sName{ get; set; } got automatically created. Now I change the column

“EntityType has no key defined” exception although key is defined with HasKey

痞子三分冷 提交于 2019-12-07 02:48:37
问题 Using EF 5 (reverse engineered code first), my model was working fine until it suddenly stopped. \tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'ProjectsDate' has no key defined. Define the key for this EntityType. \tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'ProjectsRisk' has no key defined. Define the key for this EntityType. I define a key using fluent API rather than attributes, here is my ProjectsDates classes. public partial class ProjectsDate { public string

Visual Studio 2012 Code First still uses SQLEXPRESS by default

做~自己de王妃 提交于 2019-12-07 02:38:12
问题 I created a brand new Web API project, created a simple Code First model (one class with an id and the dbcontext object, and that's it), and ran Enable-Migrations in the package manager console. I noticed that it creates the database in SQLEXPRESS rather than LocalDB, despite the DefaultConnection string pointing to (LocalDB) in the Web.config file. This causes subsequent queries to fail, claiming that the database hasn't been initialized. How do I get the Enable-Migrations command in VS 2012

Is it bad practice to filter by ID within the repository pattern

江枫思渺然 提交于 2019-12-07 02:35:52
问题 I am using ASP.NET MVC4 with Entity Framework 5 . Essentially every controller action result filters the db results by the logged in Users' Company ID . I have just begun implementing a repository pattern to return the models rather than directly filtering the DbContext from the controller. (Passing the companyID into the repository to filter results of methods) I have a funny feeling that it is bad practice to do this, but have been unable to find any information on the subject. I will

Entity Framework doesn't query derived classes - Error in DbOfTypeExpression

痞子三分冷 提交于 2019-12-07 02:34:46
问题 I have a base class and two derived classes. Each of the derived classes implements the same type as a property - the only difference is the property name. Sadly I don't have much influence on the class design -> they have been generated from a wsdl file. I then have a property on the BaseType to encapsulate the common property. The plan was to use this property in my web views etc. I have used the famous "Fruit-Example" to demonstrate the problem: public class FruitBase { public virtual int

Retaining Form Values After Post (not part of model)

允我心安 提交于 2019-12-07 02:13:36
问题 I have a MVC4 page that has a form with a collection of checkboxes, radio buttons and textboxes used as the search fields. Upon post the selections are parsed and the lower results grid is updated with new results. Right now all the form values are wiped out upon return and the new results are displayed in the grid - only the grid is part of the model. I want all the form selections to retain their values after post so the user can see (and change) the selections for next post/search. The

Entity Framework Skip method running very slow

♀尐吖头ヾ 提交于 2019-12-07 01:49:00
问题 I'm using Entity Framework 5, ObjectContext and POCOs on my data access layer. I have a generic respository implementation and I have a method that queries the database with paging using Skip() and Take(). Everything works fine, except that the query performance is very slow when skipping a lot of rows (I'm talking about 170k rows) This is an excerpt of my query on Linq to Entities: C# Code: ObjectContext oc = TheOBJEntitiesFactory.CreateOBJEntitiesContext(connection); var idPred = oc

Which version of Entity Framework is used by my project?

自古美人都是妖i 提交于 2019-12-07 01:30:43
问题 I have a project using Entity Framework, but I am not sure which version of EF I am using. According to the Microsoft version history EF5 will install itself: If you create a new model using the Entity Framework Designer in Visual Studio 2012, the EF5 NuGet package will be installed to your project and the generated code will make use of EF5. However I did not create the EF-part of the project, but got it from version control (TFS). Now I am not sure how to determine if I have EF5. If I right

Entity Connection String Constructor not found in EF 5 and WCF 4.5 at runtime

不羁岁月 提交于 2019-12-07 00:28:28
I have developed web application using VS 2010, WCF 4.0 and EF 4.1.1. My WCF Service developed with multiple EF Connection strings configured in web.config file those are taken from Entity Model app.config file. based on the parameters i am redirecting databases with EF Connection string at runtime. My WCF4.0 web.config like: <connectionStrings> <add name="WMSChennaiDEVEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=192.168.0.89;Initial Catalog=WMSCMSWPROD;User ID=sa;Password