entity-framework

How can I transform this linq expression?

牧云@^-^@ 提交于 2020-01-13 03:40:08
问题 Say I have an entity that I want to query with ranking applied: public class Person: Entity { public int Id { get; protected set; } public string Name { get; set; } public DateTime Birthday { get; set; } } In my query I have the following: Expression<Func<Person, object>> orderBy = x => x.Name; var dbContext = new MyDbContext(); var keyword = "term"; var startsWithResults = dbContext.People .Where(x => x.Name.StartsWith(keyword)) .Select(x => new { Rank = 1, Entity = x, }); var

Left Join in Entity Framework 3.5

£可爱£侵袭症+ 提交于 2020-01-13 03:36:09
问题 I am trying to left join on entity frame work 3.5 but i am unable to do so... from i in (from ta in context.test_attempt join uf in context.user_flag on ta.users.USERID equals uf.UserID) select i; I want to use left join instead to join? 回答1: You need to use DefaultIfEmpty() for an outer join: from ta in context.test_attempt join uf in context.user_flag on ta.users.USERID equals uf.UserID into g from uf in g.DefaultIfEmpty() select new { ta, uf } Your outer from/select above is unnecessary,

How to perform CRUD with Entity Framework Code-First?

僤鯓⒐⒋嵵緔 提交于 2020-01-12 21:21:48
问题 I am having a really hard time updating and deleting many to many relationships with EF Code-first. I have a fairly simple Model: public class Issue { [Key] public int IssueId { get; set; } public int Number { get; set; } public string Title { get; set; } public DateTime Date { get; set; } public virtual ICollection<Creator> Creators { get; set; } } public class Creator { [Key] public int CreatorId { get; set; } public string FirstName { get; set; } public string MiddleName { get; set; }

EF6 + Postgres relation dbo.AspNetUsers does not exist

北城以北 提交于 2020-01-12 19:45:09
问题 I have been following this post on using PostgreSQL with EF6 http://www.jasoncavett.com/blog/postgresql-and-entity-framework-6-code-first/. I have started a brand new MVC5 project hoping to use Postgres in my application for backend. The application starts up fine however when you go to register a user (I selected individual authentication) I get the following error messsage ERROR: 42P01: relation "public.AspNetUsers" does not exist I am unsure as to how to resolve this problem. The error

EF6 + Postgres relation dbo.AspNetUsers does not exist

雨燕双飞 提交于 2020-01-12 19:44:40
问题 I have been following this post on using PostgreSQL with EF6 http://www.jasoncavett.com/blog/postgresql-and-entity-framework-6-code-first/. I have started a brand new MVC5 project hoping to use Postgres in my application for backend. The application starts up fine however when you go to register a user (I selected individual authentication) I get the following error messsage ERROR: 42P01: relation "public.AspNetUsers" does not exist I am unsure as to how to resolve this problem. The error

ASP.Net MVC - model with collection, Submit

僤鯓⒐⒋嵵緔 提交于 2020-01-12 19:08:31
问题 I have a Model that looks like public class Patient { private ICollection<Refill> _refills = new List<Refill>(); public int Id { get; set; } public string FirstName { get; set; } public virtual ICollection<Refill> Refills { get { return _refills; } set { _refills = value; } } public class Refill { public int Id { get; set; } public RefillActivityStatus RefillActivityStatus { get; set; } public DateTime? RefillDate { get; set; } public RefillType RefillType { get; set; } public string RXNumber

Entity Framework Table Per Type Performance

早过忘川 提交于 2020-01-12 19:05:51
问题 So it turns out that I am the last person to discover the fundamental floor that exists in Microsoft's Entity Framework when implementing TPT (Table Per Type) inheritance. Having built a prototype with 3 sub classes, the base table/class consisting of 20+ columns and the child tables consisting of ~10 columns, everything worked beautifully and I continued to work on the rest of the application having proved the concept. Now the time has come to add the other 20 sub types and OMG, I've just

Entity Framework Table Per Type Performance

匆匆过客 提交于 2020-01-12 19:04:13
问题 So it turns out that I am the last person to discover the fundamental floor that exists in Microsoft's Entity Framework when implementing TPT (Table Per Type) inheritance. Having built a prototype with 3 sub classes, the base table/class consisting of 20+ columns and the child tables consisting of ~10 columns, everything worked beautifully and I continued to work on the rest of the application having proved the concept. Now the time has come to add the other 20 sub types and OMG, I've just

Entity Framework creates underscore column when generating database

て烟熏妆下的殇ゞ 提交于 2020-01-12 18:49:33
问题 I have a simple object model as follows... public class Product { public long ProductId { get; set; } public int CategoryId { get; set; } public Category Category { get; set; } } and public class Category { public long CategoryId { get; set; } public List<Product> Products { get; set; } } Generating the underlying database with EntityFramework results in the following schema... Products ProductId CategoryId Category_CategoryId Categories CategoryId In the Products table, the CategoryId column

Entity Framework creates underscore column when generating database

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-12 18:49:25
问题 I have a simple object model as follows... public class Product { public long ProductId { get; set; } public int CategoryId { get; set; } public Category Category { get; set; } } and public class Category { public long CategoryId { get; set; } public List<Product> Products { get; set; } } Generating the underlying database with EntityFramework results in the following schema... Products ProductId CategoryId Category_CategoryId Categories CategoryId In the Products table, the CategoryId column