entity-framework-4.1

How to separate large table into multiple discrete types using EF-Code-First

為{幸葍}努か 提交于 2019-11-30 22:32:09
I am trying to separate a large table into multiple discrete types. I'm following the example here: http://weblogs.asp.net/manavi/archive/2011/04/24/associations-in-ef-4-1-code-first-part-4-table-splitting.aspx?CommentPosted=true#commentmessage It's working for a primary type and a sub-type, but does not work when I employ multiple types. I received an error The Entity types 'CampaginFeedback' and 'CampaignSurvey' cannot share table 'Campaign' because they are not int he same type hierarchy or do not have a valid one to one foreign key relationship with matching primary keys between them. Here

Entity Framework Oracle and Sql Server - how to build a database independent application

…衆ロ難τιáo~ 提交于 2019-11-30 19:22:26
We are trying to build a data access layer for using both Oracle and SQL Server (not at the same time). We use EF Model-first for creating the model and the create the SQL scripts for building the database. Our first thought was to create 2 EDMX files, one for each type, and use the appropriate one depending on the client's need. We are using the Oracle and SQL Server database generation workflow and DDL generation template to create the scripts for each database. Our main problem is when the database schema changes we do not want to drop and recreate the DB but only create the migration

view generated SQL for Entity Framewok SaveChanges command in Visual studio?

▼魔方 西西 提交于 2019-11-30 18:53:52
I can see the SQL generated by Entity Framework for select operations in Visual studio, but not for insert, update and delete. how can I see the SQL generated for "DataContext.SaveChanges" command in Visual studio while debugging? If you have visual studio ultimate you can see the updates and inserts in intellitrace. Just put a breakpoint right after SaveChanges is called. http://www.youtube.com/watch?v=fLBpZNXs-Lw If you are using it on a web project you could also use mini-profiler. http://miniprofiler.com/ Here's something really simple that I found: context.Database.Log = x => System

How to represent Bridge table in Entity Framework Code First

ⅰ亾dé卋堺 提交于 2019-11-30 18:40:47
I am trying to find out how I can represent a bridge table between two entities (many to many relation) I'm Using Entity Framework Code First Student: StudentID int PK StudentName VARCHAR(50) Class: ClassID int PK ClassName VARCHAR(50) StudentClass: StudentID INT PK ClassID INT PK What is the best Class Structure should i Use to represent it in Entity Framework Code First and how can i select from the bridge table and insert in it. Should I represent the classes it like this: public class Student { public int StudentId { get; set; } public string StudentName { get; set; } public List<Class>

Why does the Entity Framework's DbContext.Find() generate a query with select top 2?

痴心易碎 提交于 2019-11-30 18:06:08
Why does the Entity Framework's DbContext.Find() generate a query with select top 2 and a derived table? By definition, the query is looking up by primary key which should be unique. Find checks first if the entity with the given key is already in the context. If not it queries the database. Possibly it uses in this case a LINQ query using SingleOrDefault . SingleOrDefault translates to SELECT TOP 2 to be able to throw an exception if the result has more than one entity. So, why doesn't Find use FirstOrDefault (which would translate to SELECT TOP 1 ). I don't know, but I would guess that Find

TransactionScope, where is begin transaction on sql profiler?

[亡魂溺海] 提交于 2019-11-30 17:48:19
i need to do something like this on a transaction context using(var context = new Ctx()) { using (TransactionScope tran = new TransactionScope()) { decimal debit = 10M; int id = 1; var data = context.Cashier .Where(w => w.ID == id) .Select(s => new{ s.Money }) .Single(); Cashier cashier = new Cashier(){ ID = id }; context.Cashier.Attach(cashier); cashier.Money = data.Money - debit; context.Entry(cashier).Property(p => p.Money ).IsModified = true; context.SaveChanges(SaveOptions.None); tran.Complete(); } } I'm running sql profiler but can't see begin tran, is that block of code correct? Am I

The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.Object

北城余情 提交于 2019-11-30 17:33:45
问题 Does anyone know why I am getting this error: The model item passed into the dictionary is of type system.Data.Entity.DynamicProxies.Object_3E186F803589BF82895B10E08C 2A9AB68EFA619599418D6EB96585D14874CDC0', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MyApplication.Domain.Entities.Object]'. Here is my code: Controller: public ViewResult Index() { if (User.Identity.IsAuthenticated) { MembershipUser currentUser = Membership.GetUser(); Guid

EF code-first PluralizingTableNameConvention for ONE DbSet

£可爱£侵袭症+ 提交于 2019-11-30 17:32:20
How do I toggle this convention PluralizingTableNameConvention for only a single table/DbSet? As far as I can tell, I can only do this to all the DbSets for a given DbContext If you have only one entity which is mapped to a table that is not pluralizeed then you can remove the PluralizingTableNameConvention and manually configure the table name of the entity. public class MyContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); modelBuilder.Entity<Item>()

How to separate large table into multiple discrete types using EF-Code-First

眉间皱痕 提交于 2019-11-30 17:19:02
问题 I am trying to separate a large table into multiple discrete types. I'm following the example here: http://weblogs.asp.net/manavi/archive/2011/04/24/associations-in-ef-4-1-code-first-part-4-table-splitting.aspx?CommentPosted=true#commentmessage It's working for a primary type and a sub-type, but does not work when I employ multiple types. I received an error The Entity types 'CampaginFeedback' and 'CampaignSurvey' cannot share table 'Campaign' because they are not int he same type hierarchy

EF 4.1 - Model Relationships

混江龙づ霸主 提交于 2019-11-30 17:08:18
I'm trying to create a quick ASP.NET MVC 3 application using the RC version of EF 4.1. I have two models: public class Race { public int RaceId { get; set; } public string RaceName { get; set; } public string RaceDescription { get; set; } public DateTime? RaceDate { get; set; } public decimal? Budget { get; set; } public Guid? UserId { get; set; } public int? AddressId { get; set; } public virtual Address Address { get; set; } } and public class Address { public int AddressId { get; set; } public string Street { get; set; } public string StreetCont { get; set; } public string City { get; set;