entity-framework

How to make persisted computed column in EF code first?

瘦欲@ 提交于 2020-01-10 02:52:08
问题 How do I get this column as similar to a PERSISTED COMPUTED column in the database? My current attempt (it loads all CompCol rows with null in seed) : public class Call { public Call() { } [Key] public int Id { get; set; } [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public string CompCol { get { return "ABC-" + Convert.ToString(Id).PadLeft(5, '0'); } protected set {} } } 回答1: The solution I found was to : Make sure auto migrations are turned off. This is so that VS will generate a

Entity Framework: LINQ to Entities only supports casting Entity Data Model primitive types

旧街凉风 提交于 2020-01-10 02:20:13
问题 I wrote a method to allow for an Expression to be passed in for the orderby clause, but I ran into this problem. Unable to cast the type 'System.DateTime' to type 'System.IComparable'. LINQ to Entities only supports casting Entity Data Model primitive types. Basically the expression is this: Expression<Func<K, IComparable>> orderBy And is used like this: SomeEntities.SomeTable .Where ( whereClause ) .Select ( selectClause ) .OrderBy(orderBy) The idea is so that I can use a dictionary to hold

ObservableCollection better than ObjectSet

情到浓时终转凉″ 提交于 2020-01-10 02:04:32
问题 Why is it better (in WPF, C#, Entity Framework) to bind ListBox to an ObservableCollection created upon the ObjectSet (from Entity Framework) rather than binding to ObjectSet directly? One more question: When I bind ListBox to ObservableCollection , any additions to the collection updates ListBox . Great. But ObservableCollection was created upon ObjectContext (in Entity Framework) and adding a new item to the collection doesn't add the item to the context... how to solve this???? 回答1:

Mapping SQL view in code-first approach

你离开我真会死。 提交于 2020-01-10 01:04:08
问题 I have a SQL view: WITH DirectReports (ID,ParentFolderID, ParentFolderName,FolderID,FolderName,OwnerOCID,OwnerArName,OwnerEnName,FolderType,LEVEL) AS ( SELECT e.Id AS ID,cast(cast(0 AS binary) AS uniqueidentifier) AS ParentFolderID, cast('MainFolder - ' + MainFolders.enName AS nvarchar(250)) AS ParentFolderName, e.Id AS FolderID, e.Name AS FolderName, WorkSpaces.Owner_Id AS OwnerOCID, OrgCharts.arName AS OwnerArName, OrgCharts.enName AS OwnerEnName, MainFolders.Type AS FolderType, 0 AS LEVEL

Code-First Entity Framework w/ Stored Procedure returning results from complex Full-text Searches

谁说胖子不能爱 提交于 2020-01-09 13:01:16
问题 I am looking for design advice for the following scenario: I have a code-first EF5 MVC application. I am building a full-text search function which will incorporate multiple weighted columns from many tables. As I cannot create view with an index from these tables (some of them contain text / binary columns), I have created a stored procedure which will output the ID of my object (eg. PersonID ) and the rank associated with that object based on the search terms. My current approach is to

Multiplicity constraint violated Entity framework 5

淺唱寂寞╮ 提交于 2020-01-09 11:38:25
问题 Hello i have 3 classes Person, UserProfile(it inherits Person) and Results, a Person can have one or more results, when i try to add i a result to a person a i get the error mentioned in the title, my classes are bellow. Any help would be appreciated. [Table("People")] public class Person : IPerson { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Name {

Multiplicity constraint violated Entity framework 5

烈酒焚心 提交于 2020-01-09 11:38:00
问题 Hello i have 3 classes Person, UserProfile(it inherits Person) and Results, a Person can have one or more results, when i try to add i a result to a person a i get the error mentioned in the title, my classes are bellow. Any help would be appreciated. [Table("People")] public class Person : IPerson { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Name {

EF property of type List<enum> not created in db

柔情痞子 提交于 2020-01-09 11:19:19
问题 I'm developing an ASP.NET MVC5 application using code first EF. My code: public enum Language : byte { [Display(Name = "Turkmen")] TKM = 1, [Display(Name = "Russian")] RUS = 2, [Display(Name = "Chineese")] CHN = 3, [Display(Name = "English")] ENG = 4 } And my model class is: public class Person { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int PersonID { get; set; } [Required] public string Name { get; set; } [Required] public string Surname { get; set; }

EF property of type List<enum> not created in db

给你一囗甜甜゛ 提交于 2020-01-09 11:18:25
问题 I'm developing an ASP.NET MVC5 application using code first EF. My code: public enum Language : byte { [Display(Name = "Turkmen")] TKM = 1, [Display(Name = "Russian")] RUS = 2, [Display(Name = "Chineese")] CHN = 3, [Display(Name = "English")] ENG = 4 } And my model class is: public class Person { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int PersonID { get; set; } [Required] public string Name { get; set; } [Required] public string Surname { get; set; }

Entity Framework Include with condition

微笑、不失礼 提交于 2020-01-09 11:17:51
问题 I need to filter a dealer based on id and the uncomplete checkins Initially, it returned the dealer based only on id: // TODO: limit checkins to those that are not complete return this.ObjectContext.Dealers .Include("Groups") .Include("Groups.Items") .Include("Groups.Items.Observations") .Include("Groups.Items.Recommendations") .Include("Checkins") .Include("Checkins.Inspections") .Include("Checkins.Inspections.InspectionItems") .Where(d => d.DealerId == id) .FirstOrDefault(); As you can see