Tag: entity-framework

EF can't SaveChanges to db

I try to create an Equation entity and to add it to SQL Server db, i do not get any errors in my code but i do not see any changes in the db. I check the db in the server explorer in visual studio, and there are not added values. The db were added […]

Cascade Update in Entity Framework

I have the following scenario involving 2 classes: public class Parent { [Key] public int Id {get;set;} //.. Other properties here public virtual IList<Child> Children {get;set;} } and public class Child { [Key] public int Id {get;set;} public int ParentId {get;set;} //.. Other properties here [ForeignKey(“ParentId”)] public virtual Parent {get;set;} } I also have an […]

Cannot insert the value NULL into column 'Id' (Database first)

Database-first solution. I’m using two tables called User and Profile. They are both using uniqueidentifier (SQL Server) as their primary key. The way I let User to automatically receive it’s own guid id was from: Open my edmx file. Right click the Guid column for User -> Properties -> change the StoreGeneratedPattern to Identity. Worked […]

Add stored procedure to Entity Framework

This question already has an answer here: EF4 – The selected stored procedure returns no columns 12 answers

Mapping one to many relationship to existing database views without keys

I need to create one to many relationship between two classes.Database do not contains primary or foreign keys. So i decided to create 2 views instead of 3 tables, and views also has no primary/foreign key (Changing the database schema is not allowed) Views [Table(“Barcode”)] public partial class Barcode { [Column(“_Barcode”)] public string _Barcode { […]

Add item and update relationship in transitional table in many-to-many database Sql Server

–here was wrong model without association manyTOmany between A-B. corrected is in EDIT2– A exists in database, B exists in database. I need only enter new C element with some Properties1 and Properties2 (and update collections of C in existed A and B elements) I tried many options, like for example this, but still somethings […]

WCF/Entity Framework with External SQL Server DB Does Not Work when Deployed to IIS

I have a simple WCF project that uses the Entity Framework to access the AdventureWorks database. Its actually out of a book Windows Communication Foundation 4: Step by Step. The catch is that the SQL Server database is not a local SQL Server Express instance but a full SQL Server 2008 R2 instance on an […]

A dependent property in a ReferentialConstraint is mapped to a store-generated column – when saving object

Every time I try to save something into the database I get the error: A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: ‘PackageId’. Following is the code that does this, the line DB.SaveChanges();. public ActionResult CreatePackage(Package package, string MaterialId, string SubCategoryId, string Companies) { ModelState.Clear(); //add stuff to package package.CreatedDate […]

Is it possible to have a EF Context for MySql and SqlServer?

I have two entity framework contexts, one for MySql and one for sql. If I run the app I get the following error The default DbConfiguration instance was used by the Entity Framework before the ‘MySqlEFConfiguration’ type was discovered. However if I do discover the database type on app start by giving it the Database.SetInitializer<MySqlContext>, […]

Linq To Sql using AttachAll. DuplicateKeyException

I searched for the answer on the website but I did not find one. I have the following problem … I’m trying to update multiple records in the database as follows: public void SaveJItem(List<DataForDespatcher> Jitem) { JitemsTable.InsertAllOnSubmit(Jitem.Where(i => i.Id ==0)); JitemsTable.AttachAll(Jitem.Where(i => i.Id != 0)); JitemsTable.Context.Refresh(RefreshMode.KeepCurrentValues, Jitem); JitemsTable.Context.SubmitChanges(); } The table is described as follows: […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.