entity-framework-5

Entity Framework Database first How to alter entities to make them derive from a base class

徘徊边缘 提交于 2019-12-10 14:18:29
问题 I have a database already full of tables with data in them. What I have seen is that all tables have 5 columns in common: Id-long, key IsDeleted, bit DateDeleted, SmallDatetime LastUpdated, SmallDatetime LastUpdatedUser, nvarchar Now, there are some common operations that are done based on those fields which currently are replicated everywhere What I want is to create a base class containing just these common attributes and the methods done to them and make every other entity derive from this

Entity Framework Connection String Definition

佐手、 提交于 2019-12-10 14:07:57
问题 I was just wondering that, what is Entity Framework Connection String really mean? Like: metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=testSource;initial catalog=CatalogName;user id=sa;password=***********;multipleactiveresultsets=True;application name=EntityFramework" I am aware of provider=System.Data.SqlClient; provider connection string="data source=testSource; initial catalog

contains cycles and cannot be serialized if reference tracking is disabled, json.net and webapi

拈花ヽ惹草 提交于 2019-12-10 12:35:18
问题 I'm getting the error: Object graph for type 'System.Collections.Generic.List`1[[Proj.Model.Prom, Proj.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' contains cycles and cannot be serialized if reference tracking is disabled. Reading about that, seems to be the serializer, but Json.Net claims to be the solution and I've read WebApi and Framework 4.5 has it by default. So Is it coming by default? If so, Why I'm still getting that error? Thanks! Guillermo. EDIT: Adding code

Seeding EF Database in a Separate DAL Project

独自空忆成欢 提交于 2019-12-10 11:58:48
问题 I'm starting a new ASP.NET project, and I'm trying to follow the multi-project approach I've seen mentioned in multiple questions around Stackoverflow. I've been following this tutorial, but it assumes only one project for your entire solution. Most notably, it recommends modifying your Global.asax file with code to set the database initializer. Seeing as how my DAL project doesn't have a Global.asax file, what is the correct procedure for seeding the initial EF database? 回答1: I stand

Using UserProfile foreign key in class creates new profiles in MVC 4

末鹿安然 提交于 2019-12-10 10:56:06
问题 I'm trying to make a basic website that uses the built in MVC user profile as the authentication method. I'm using MVC4.0 and Entity Framework. I have a main data class that uses the UserProfile model as a foreign key. This class is a "game" class, for the purpose of relating a game to a certain user. I've also added another member to the UserProfile class, as a necessity for this project. Every time I try to add a new game, which has a user's profile in it as a foreign key, the server ends

Entity Framework & WPF Datagrid binding

拥有回忆 提交于 2019-12-10 10:44:51
问题 I have a pretty simple little app that is using EF and WPF. I'm trying to create a very lightweight 'project tracker' for our small team at work. The classes look like: class Project { public int ProjectId { get; set; } public string Name { get; set; } public List<ProjectNote> ProjectNotes { get; set; } public string Status { get; set; } public string Description { get; set; } public string ProjectLead { get; set; } } class ProjectNote { public int ProjectNoteId { get; set; } public DateTime

Entity Framework get user from contex in saveChanges

…衆ロ難τιáo~ 提交于 2019-12-10 10:42:55
问题 i have two projects in my solution, UI as mvc and class project for entitiy model code first. I have severall entities in my model but now I need to extend them by new audit fields where I need to save who changed entity. I added new interface public interface IAuditable { /// <summary>Gets or sets the name.</summary> /// <value>The name.</value> DateTime CreatedDate { get; set; } /// <summary>Gets or sets the name.</summary> /// <value>The name.</value> string CreatedBy { get; set; } ///

How to create and use a generic class EntityTypeConfiguration<TEntity>

随声附和 提交于 2019-12-10 10:36:35
问题 Code I have two very simple interfaces in my application Represents entities that are saved in the database public interface IEntity { int Id { get; set; } } Entities that have only the Nome field as required field to save the entity public interface IEntityName : IEntity { string Nome { get; set; } } And many classes implementing this interface public class Modalidade : IEntityName { public int Id { get; set; } public string Nome { get; set; } } public class Nacionalidade : IEntityName {

Does Entity Framework(EF5) support XML data type yet?

ぐ巨炮叔叔 提交于 2019-12-10 10:28:20
问题 I am thinking of using the XML data type in SQL Server 2008 R2, but also using EF with MVC. Does EF5 support the XML data type? If not then I will have to opt for a different DB design. Many thanks. 回答1: EF does not support Xml type natively at the moment 来源: https://stackoverflow.com/questions/13031041/does-entity-frameworkef5-support-xml-data-type-yet

Entity Framework Code First Migration Class File

瘦欲@ 提交于 2019-12-10 10:27:08
问题 I'm building an application using ASP.NET MVC 4 with Entity Framework 5.0. I've recently learned about EF Code-First Migrations tool you can implement on your application for your database. I ran "Enable-Migration" in the PM Console, and it enabled successfully and created the "InitialCreate.cs" class as expected with the appropriate up() and down() methods filled in with the table creations. Then I went ahead and added another class (Category.cs) with 2 simple properties (id, name) and