entity-framework-4.3

Oracle ODP.Net and EF CodeFirst - edm.decimal error

雨燕双飞 提交于 2019-11-29 11:15:59
I have the following simple entity: public class Something{ [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public int ID { get; set; } public string NAME { get; set; } public int STATUS { get; set; } } As you can see, I do not want the ID is generated from the database but I'm going to enter manually. This my DbContext class: public class MyCEContext : DbContext { ... public DbSet<Something> Somethings { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { string dbsch = "myce"; modelBuilder.Entity<Something>().ToTable("SOMETHING", dbsch); } } There is

EF Code First cascade delete and update?

萝らか妹 提交于 2019-11-29 09:53:39
My entities are these: public class Customer { public Customer() { Invoices = new List<Invoice>(); Payments = new List<Payment>(); } public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public IList<Payment> Payments { get; set; } } public class Payment { public int ID { get; set; } public int CustomerID { get; set; } public decimal CreditPrice { get; set; } public decimal DebitPrice { get; set; } public DateTime PaymentDate { get; set; } [ForeignKey("CustomerID")] public Customer Customer { get; set; } } and this is my context: public class

Entity Framework enumerating SqlQuery result

强颜欢笑 提交于 2019-11-29 09:12:00
I have strange error while I am trying to view results of SqlQuery: var sql = "SELECT @someParam"; var someParamSqlParameter = new SqlParameter("someParam", "Some Value"); var result = _dbContext.SqlQuery<string>(sql, someParamSqlParameter); var containsAnyElements = result.Any(); So when debugger is at last line and when I try to expand Results View of result it shows me expected result("Some Value") but on invoking last line I got an exception "The SqlParameter is already contained by another SqlParameterCollection.". It looks like when I try to open Result View of result it invokes this

Is it always better to use 'DbContext' instead of 'ObjectContext'?

不打扰是莪最后的温柔 提交于 2019-11-29 06:23:30
I just downloaded EntityFramework.dll v4.3 . I've found a number of questions that compare DbContext vs. ObjectContext . But most of these are from 2010, or early 2011. I'd like to read more on the subject. Specifically, are there any books on DbContext I can get my hands on? I also want to know, as of today, what are the limitations of DbContext when comparing it to its older brother the ObjectContext ? I realize that DbContext is more compact in that it exposes fewer properties. This suggests to me that I should migrate from ObjectContext . But, if I do this migration, will I give up any

EntityFramework Code First - Check if Entity is attached

牧云@^-^@ 提交于 2019-11-29 05:27:06
I am trying to update an entity with a FK relationship in EntityFramework 4.3 Code First. I try to attach to the related entites by calling: Entry(item).State = EntityState.Unchanged I get the following exception: An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key. I do not update these items nor have an id property for them on my main entity. Is it possible to know which entities are attached or not ? Thanks in advance, Radu Tri Q Tran You can find the answer here . public bool Exists<T>(T entity) where

How to fix: The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical?

假如想象 提交于 2019-11-29 04:53:22
问题 I am using Entity Framework 4.3.1 against a SQL Server 2012 database and I am using the POCO approach. I am getting the following error and I am wondering if anyone can explain how to fix it: ModelValidationException One or more validation errors were detected during model generation: \tSystem.Data.Entity.Edm.EdmAssociationConstraint: : The number of properties in the Dependent and Principal Roles in a relationship constraint must be identical. There is no InnerException available for any

Keyword not supported: 'metadata'.? with Sql Connection in Entityt Framework with MVC3

心不动则不痛 提交于 2019-11-29 01:29:58
I am using Entity Framework 4 with my Asp.Net MVC3 application. My problem is that I am using Entity Framework to perform action with my database , That is working fine. For some other purpose I am also using Sql Connection to Store and Retrieve my data from database. I am getting [Keyword not supported: 'metadata'] error while connecting with my database. This is my web config <add name="VibrantEntities" connectionString="metadata=res://*/Vibrant.csdl|res://*/Vibrant.ssdl|res://*/Vibrant.msl;provider=System.Data.SqlClient;provider connection string="data source=KAPS-PC\KAPSSERVER;initial

How to create database using code first migrations?

泪湿孤枕 提交于 2019-11-28 21:18:35
I'm having ASP.NET MVC 3 project that uses Entity Framwork 4.3 and its migrations. Now I want Entity Framework to create a database for me using migrations that I have already. When I trying to run Update-Database script it gives me the following: Update-Database -Verbose -ProjectName AssemblyWithMigrations -StartUpProjectName WebProjectAssembly No migrations configuration type was found in the assembly '/* my name of assembly */'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration). But, when I'm trying to run Enable

How to seed data with AddOrUpdate with a complex key in EF 4.3

随声附和 提交于 2019-11-28 15:50:54
I am trying to seed a development database with some test data. I have used context.People.AddOrUpdate(p => p.Id, people)); with much success. I have another table that I need to seed, in which I would not know the primary key. For example, I would want to AddOrUpdate based on the First and Last names matching. I am unsure how to write the Expression correctly. context.People.AddOrUpdate(p => p.FirstName && p.LastName, people); is obviously incorrect, but I hope it conveys the solution I am looking for. Try this: context.People.AddOrUpdate(p => new { p.FirstName, p.LastName }, people); If you

How to manage Migrations in a project with multiple branches?

限于喜欢 提交于 2019-11-28 15:19:26
I have an ASP.NET MVC3 project that uses Entity Framework 4.3 with the code-first approach. I use Migrations to keep the database up-to-date. The project is under source-control and I have a number of branches. What I just realized is that there will be a problem when I want to merge one of my branches into the master. Since I have created migration-files in both branches, there will be overlapping migrations when I merge, which will probably cause conflicts. Is there a good way to manage Migrations in a project with multiple branches? Update One way would be to merge, then delete all