entity-framework-4

Entity Framework (EF6) + MySql Database First Model Many to Many Relationship Wrong Query Generation

巧了我就是萌 提交于 2020-01-06 20:02:42
问题 I have a project which has an existing database structure and data. Currently project is running on PHP + MySQL and I'm trying to switch from PHP to C# EF 6.0 + MySQL Database first approach. I have installed NuGet Packages (EF 6.0 and MySQL.Data, MySQL.Web, MySQL.Data.Entity, MySQL.Data.Entities) and modified my app.config according to use MySQL data provider. Up to this state everything works perfectly, I can generate model from database and can insert data on each table without any issue

How to create and populate a nested ViewModel well

风格不统一 提交于 2020-01-06 19:54:53
问题 I have a View Model that has some serious nesting. I need to populate it from Entity Framework 4. I tried creating one big linq statement to populate it, but it says it doesn't recognize the .ToList() methods. It compiles fine. Runtime error is LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[ProductDepartment] ToList[ProductDepartment] (System.Collections.Generic.IEnumerable`1[ProductDepartment])' method, and this method cannot be translated into a store

Filter base entity from child entities' properties

六月ゝ 毕业季﹏ 提交于 2020-01-06 14:54:09
问题 I have been looking for a solution for days now. I have eight entities in my application, a base and seven entities that inherits from this base entity. Some of the child entities have same properties. public class LogEntry(){ public int LogEntryId{get;set;} public string ... } public class TestEntry : LogEntry{ .... public string SomeProperty{get;set;} //SomePropertyThatIsNotInBaseClass .... } public class XEntry : LogEntry{ .... public string SomeProperty{get; set;} .... } I am trying to

EF 4.3 code first - How to set default value

给你一囗甜甜゛ 提交于 2020-01-06 14:19:08
问题 I'm having an entity like that: public class Part : Entity { public int Id { get; set; } public string Name { get; set; } public IEnumerable<VersionSection> VersionSections { get { return Sections.Where(s => s is VersionSection).Cast<VersionSection>(); } } public virtual ICollection<Section> Sections { get; set; } public Part() { this.Sections = new List<Section>(); } } I would like to set the default value for the Sections collection very time when I create a new instance of Part following

Asp.Net MVC3 adding search functionality

删除回忆录丶 提交于 2020-01-06 13:09:00
问题 I am trying to implement search functionality on a list of customers, the functionality is detailed in this tutorial on the Asp.Net site, http://www.asp.net/entity-framework/tutorials/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application In my controller i have the following public ViewResult Index(string sortOrder, string searchString) { ViewBag.CustomerNameSortParm = String.IsNullOrEmpty(sortOrder) ? "CustomerName desc" : ""; ViewBag.PrimaryContactNameSortParm

Asp.Net MVC3 adding search functionality

半城伤御伤魂 提交于 2020-01-06 13:08:21
问题 I am trying to implement search functionality on a list of customers, the functionality is detailed in this tutorial on the Asp.Net site, http://www.asp.net/entity-framework/tutorials/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application In my controller i have the following public ViewResult Index(string sortOrder, string searchString) { ViewBag.CustomerNameSortParm = String.IsNullOrEmpty(sortOrder) ? "CustomerName desc" : ""; ViewBag.PrimaryContactNameSortParm

Deep Clone using Entity Framework

北战南征 提交于 2020-01-06 12:55:10
问题 How to create Deep Clone from objects returned via Entity Framework ? The source object also have some other collections associated with it. In other words, how to clone an entity returned from Entity Framework ? 回答1: Just like how we deep clone any other objects. You need override the clone on source object and provide a implementation by copying each memberwise. http://msdn.microsoft.com/en-us/library/system.object.memberwiseclone.aspx How do you do a deep copy of an object in .NET (C#

Ado.net EDMX model table fields custom validation

▼魔方 西西 提交于 2020-01-06 10:34:26
问题 I have generated the data table model using the option "Generate model from database" in the entity framework and now the model contains the IDE generated code of the models. The models are working fine and now I have a problem, because I want to add custom validations to the table fields and the error messages & the field names should be taken from the resource file. The validation should be done in the ajax call. Can anyone help me to add these validations to the automatically generated

Ado.net EDMX model table fields custom validation

给你一囗甜甜゛ 提交于 2020-01-06 10:33:37
问题 I have generated the data table model using the option "Generate model from database" in the entity framework and now the model contains the IDE generated code of the models. The models are working fine and now I have a problem, because I want to add custom validations to the table fields and the error messages & the field names should be taken from the resource file. The validation should be done in the ajax call. Can anyone help me to add these validations to the automatically generated