entity-framework-6

Prevent Entity Framework adding ORDER BY when using Include

微笑、不失礼 提交于 2020-01-01 01:53:13
问题 We have a query similar to the following: from x in db.Table.Include(x => x.Parent) .Include(x => x.Parent.Relation) .Include(x => x.Relation) .Include(x => x.Children) where /* some query */ select x The problem is that when adding .Include(x => x.Children) , the ORDER BY statement that Entity Framework adds to the generated SQL causes the query to take a long time to execute - something like the below: ORDER BY [Project2].[Id1] ASC, [Project2].[Id2] ASC, [Project2].[Id] ASC, [Project2].[C4]

project.Models.tableName:The field pvid must be a string or array type with a maximum length of '20'

╄→гoц情女王★ 提交于 2019-12-31 07:14:40
问题 I encounter exception error below when i try to add a new entry in the database with : db.patient_visit.Add(pv); db.SaveChanges(); An exception of type 'System.InvalidOperationException' occurred in project.dll but was not handled in user code Additional information: project.Models.tableName:The field pvid must be a string or array type with a maximum length of '20'. Before this, my model is automatically and originally set like below because i did Code-First migration with existing database.

Visual Studio 2015 Error. The default XML namespace of the project must be the MSBuild XML namespace

。_饼干妹妹 提交于 2019-12-31 05:28:06
问题 (Let me preface the question with Yes, I have seen similar questions, but not exactly my scenario.) My environment is Microsoft Visual Studio Professional 2015 (version 14.0.25431.01 Update 3) My actions I create a new C# Class Library Project; (Ok) It defaults to .NET Fx 4.5.1, I change it to the latest on my machine Fx 4.7.2; (Ok) I Build / Compile it; (Ok) I go to the Manage NuGet Packages menu, search for EntityFramework, and try to install the latest; it tells me it is EF 6.3.(Ok) Hit

Materializing an ICollection structure containing subclasses

半世苍凉 提交于 2019-12-31 05:20:49
问题 I'm reviewing some code that was written in the EF 4 days because it stands out during performance benchmarking. The purpose of the code is to materialize an ICollection<MyBaseClass> using Entity Framework (we're now on EF 6.1). The code exists because references present in specific subclasses aren't materialized when retrieving public Parent { public virtual ICollection<MyBaseClass>() Base { get; set; } } from the database, when the actual types stored are subclasses of MyBaseClass. Example

Seeding method is inserting additional Entities with NULL values

房东的猫 提交于 2019-12-31 05:14:54
问题 I am having this strange behavior all of a sudden (i have compared my files in version control (tfs) to be sure i did not change anything and i didn't found anything different). I am seeding my database with some metadata and i see that it has a very strange behavior i never saw before. I am inserting a Entity "Product" and it inserts this entity 2 times , first insert is correct and has everything it should have, the other one has NULL properties (string values) but some (like datetimes)

Does SQL Server automatically trim nvarchar fields upon query?

倾然丶 夕夏残阳落幕 提交于 2019-12-31 01:07:28
问题 I have this query : select '[' + p.Firstname + ']' from Person p where p.Firstname = 'Johanne' In the table, I have multiple personne who have this firstname, and some have a trailing space on the value (bad insertion of the values, it will be corrected). Why then does this query bring me this result (I inserted the brackets to visualize the spaces) : [Johanne] [Johanne ] [Johanne ] [Johanne] Is this a configuration thing ? The real query comes from entity framework 6, but this example does

Does SQL Server automatically trim nvarchar fields upon query?

半腔热情 提交于 2019-12-31 01:07:05
问题 I have this query : select '[' + p.Firstname + ']' from Person p where p.Firstname = 'Johanne' In the table, I have multiple personne who have this firstname, and some have a trailing space on the value (bad insertion of the values, it will be corrected). Why then does this query bring me this result (I inserted the brackets to visualize the spaces) : [Johanne] [Johanne ] [Johanne ] [Johanne] Is this a configuration thing ? The real query comes from entity framework 6, but this example does

EF 6 with a dnx project

允我心安 提交于 2019-12-30 17:27:24
问题 I have a new ASP.net 5 dnx class library I am using for entity framework. I need to target EF 6 because some features I need are not in EF 7. First the EF tools (like enable-migration) were not there. I added an old style class library and installed EF 6 and now the commands are there. When I run enable migrations I get this error: PM> Enable-Migrations Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'

EF 6 with a dnx project

。_饼干妹妹 提交于 2019-12-30 17:27:08
问题 I have a new ASP.net 5 dnx class library I am using for entity framework. I need to target EF 6 because some features I need are not in EF 7. First the EF tools (like enable-migration) were not there. I added an old style class library and installed EF 6 and now the commands are there. When I run enable migrations I get this error: PM> Enable-Migrations Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'

Projecting self referencing multi level Entities In Entity Framework 6

徘徊边缘 提交于 2019-12-30 10:13:58
问题 Projecting self referencing multi level entities in Entity Framework 6. Let's say that I have a Category entity as follows: public class Category { public int CategoryId { get; set; } public int? ParentCategoryId { get; set; } public string Name { get; set; } public string Description { get; set; } public virtual Category ParentCategory { get; set; } public virtual ICollection<Category> SubCategories { get; set; } public virtual ICollection<Product> Products { get; set; } public Category() {