ef-code-first

Entity Framework 4.1 Code First Freeze

南楼画角 提交于 2019-12-08 09:59:31
I'm having trouble getting EF 4.1 working on my computer. It seems to be some problem with my database settings. I was trying out this simple walkthrough: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx But when it reaches db.Categories.Add(food); it just freeze. I have a normal SQL Server 2008 R2 installed, not SQL Express. There also seems to be some problems with creating .mdf files instead of a direct connection to the localhost SQL server. I've also tried adding an entity model with a database connection, but this does not seem to work. Do anyone have

How to specify two navigation relations for ef/breeze (“Unable to determine a valid ordering”)?

北战南征 提交于 2019-12-08 09:23:50
问题 I reverence an entity "monitoring" in two ways: As part of a list of monitorings in a company As active (= currently selected) monitoring of a company public class Company { [Key] [DataMember] public virtual Guid CompanyId { get; set; } [DataMember] public virtual Guid? MonitoringId { get; set; } [DataMember] [ForeignKey("MonitoringId")] public virtual Monitoring ActiveMonitoring { get; set; } [DataMember] public virtual ICollection<Monitoring> Monitorings { get; set; } } public class

How can I do TDD and Unit Testing for EF Code First entity declaration and mapping?

亡梦爱人 提交于 2019-12-08 09:18:29
问题 I have am about to retro-code a suite of unit tests for a new MVC4 app. Because nearly all my code in the EF data project is copied straight from code generated by the VS2012 EF Reverse Engineering tool, I have decided to skip unit tests in this part of the application, unless I can somehow automatically generate them. I have no business logic at here and I would like to first concentrate my efforts on ensuring better QA on the business side. But, I would like to know how one goes about first

How to alter column to identity using entity framework dbmigration?

喜你入骨 提交于 2019-12-08 08:24:31
问题 I reverse engineered a small database using Entity Framework 5.0 and the power tools. Then I started developing a website. I hit a problem because I had forgotten to make the ID column on one of my tables an IDENTITY column. So I added a code first migration and ran it using the update-database command in the package manager console. Here is the "Up" method I wrote: public override void Up() { Sql("DELETE FROM dbo.Sections"); Sql("DELETE FROM dbo.QuestionInstances"); DropForeignKey("dbo

ASP.NET MVC/EF Code First error: Unable to retrieve metadata for model

戏子无情 提交于 2019-12-08 08:23:30
I'm trying to create a controller in MVC4 and I'm getting an error I don't understand (I'm new to MVC). It says "Unable to retrieve metadata for 'CIT.ViewModels.DashboardViewModel'..." and then gives 2 possible problems. One is that the DashboardViewModel has no key defined. The other is that EntitySet 'DashboardViewModels' has no key defined. I defined a key for DashboardViewModel, but that didn't solve the problem. Here is my DashboardViewModel; public class DashboardViewModel { public DashboardViewModel() { } [Key] public int Id { get; set; } public Hardware Hardware { get; set; } public

How to configure ProviderManifestToken for EF CodeFirst in a Connection String

痞子三分冷 提交于 2019-12-08 08:16:35
问题 Currently, I'm passing a database name to the constructor of DbContext . In the connectionStrings section of my App.Config file, I've added a connection string and specified the provider name: <connectionStrings> <add name="myConnectionString" connectionString="[..]" providerName="System.Data.SqlClient"/> </connectionStrings> Now, I want to get the connection string from an other kind of configuration source, but a ProviderIncompatibleException is thrown. The exception contains the following

Generic classes in EF Code First

徘徊边缘 提交于 2019-12-08 07:56:31
问题 I’m trying to incorporate EF in my application. I use EF6 and Code First. My object model has some generic classes and it seems that Code First accepts it partially (tables and columns are generated correctly). Below an example: public class Group : TimeableObject<GroupTimeline> {} public class GroupTimeline : TimelineBase { public GroupTimeline() { } public string Name {get; set;} } public abstract class TimelineBase { public int Id { get; set; } public DateTime BeginDate { get; set; }

define scalar function with ef4.1 code first?

血红的双手。 提交于 2019-12-08 07:12:45
问题 i have a function called distancebetween i wnat to define it in scalar valued function to call it by linq if there is away to do that by EF4.1 code first ? 回答1: No. Code first was designed as "code first" = you will create a code and it will create a database where no database logic exists (no views, stored procedures, triggers or functions). Because of that it is completely missing features for mapping database logic like functions and stored procedures. If you want to use it in LINQ you

Are navigation properties read each time they are accessed? (EF4.1)

此生再无相见时 提交于 2019-12-08 06:37:58
问题 I am using EF 4.1, with POCOs which are lazy loaded. Some sample queries that I run: var discountsCount = product.Discounts.Count(); var currentDiscountsCount = product.Discounts.Count(d=>d.IsCurrent); var expiredDiscountsCount = product.Discounts.Count(d=>d.IsExpired); What I'd like to know, is whether my queries make sense, or are poorly performant: Am I hitting the database each time, or will the results come from cached data in the DbContext? Is it okay to access the navigation properties

Lambda Expression for Many to Many realtionship in C# EF 5 Code First

自古美人都是妖i 提交于 2019-12-08 06:33:29
问题 I'm using EF 5 Code First and VS 2012. I have classes for Articles and Tags. Each Article will have atleast one Tag associated. Please see the classes below. public class Article { public int ArticleId { get; set; } public virtual ICollection<ArticleTag> Tags { get; set; } } public class Tag { public int TagId { get; set; } public string TagName { get; set; } } public class ArticleTag { public int ArticleId { get; set; } public int TagId { get; set; } // navigation property public virtual