entity-framework-6

NullReferenceException in EF 5-6.1.1 with two navigation properties to the same type

眉间皱痕 提交于 2020-01-23 07:53:27
问题 I'd like to start with that I have a workaround for this issue - but I spent a few hours today figuring out the cause of the exception, so I'd thought I'd share Given two entities in the domain: public class User { public int Id { get; set; } public string Name { get; set; } } public class Ticket { public int Id { get; set; } public string Name { get; set; } public virtual User Owner { get; set; } public int? LockedByUserId { get; set; } public virtual User LockedByUser { get; set; }

Operator '>=' cannot be applied to operands of type 'string' and 'string'

二次信任 提交于 2020-01-23 05:57:48
问题 I'm using Entity Framework in C# and my code is var result = ef.services.Where(entry => entry.tarikhservice >= textBoxX1.Text && entry.tarikhservice <= textBoxX2.Text).ToList(); which gives me this error: Operator '>=' cannot be applied to operands of type 'string' and 'string' How to compare two string and fix the error? 回答1: When you compare numbers, say 1 and 2, it is clear which one is greater. However, when you compare strings, which one is considered greater: "2" or "11"? "foo" or "f"?

Invalid Column name when using savechanges() in entity framework

感情迁移 提交于 2020-01-23 04:40:13
问题 So here is the deal, I have changed my database schema, and changed the PK for one of my tables and I have removed everything related to the old PK (FK reference in another tables). However I have this exception when I insert a new entity using savechanges() method ex = {"An error occurred while updating the entries. See the inner exception for details."} And the inner exception is InnerException = {"Invalid column name 'Audit_ID'."} the Audit_ID is the old PK. I have tried this "Invalid

Dynamic query for creating where predicate with inner Collection

我只是一个虾纸丫 提交于 2020-01-22 23:03:08
问题 I am creating search capability for my MVC EF application. I am creating it using dynamic query. And following this method https://www.codeproject.com/Articles/493917/Dynamic-Querying-with-LINQ-to-Entities-and-Express Its for creating predicate for bool and string fields of entity. Main entity in my app is Applicant EDMX Applicant is following public partial class Applicant { public Applicant() { this.ApplicantEducations = new HashSet<ApplicantEducation>(); this.ApplicantSkills = new HashSet

How to implement a Unit of work containing the new IdentityUser

不羁的心 提交于 2020-01-22 22:38:09
问题 I am wondering what is the best way to add the UserManager to my Unit of work. Should I use the IUstrore interface and add a new UserManager in my controller? Should I just use UserManager in my UnitOfWork or should I do something different? Here is two ideas I had for my unit of work and controller implementation. public class UnitOfWorkPds : IUnitOfWorkPds, IDisposable { private ApplicationDbContext context = new ApplicationDbContext(); private IUserStore<ApplicationUser> userStore; public

How to implement a Unit of work containing the new IdentityUser

牧云@^-^@ 提交于 2020-01-22 22:38:08
问题 I am wondering what is the best way to add the UserManager to my Unit of work. Should I use the IUstrore interface and add a new UserManager in my controller? Should I just use UserManager in my UnitOfWork or should I do something different? Here is two ideas I had for my unit of work and controller implementation. public class UnitOfWorkPds : IUnitOfWorkPds, IDisposable { private ApplicationDbContext context = new ApplicationDbContext(); private IUserStore<ApplicationUser> userStore; public

Possible to set column ordering in Entity Framework

≡放荡痞女 提交于 2020-01-22 08:18:36
问题 Is there any possible configuration to set database column ordering in entity framework code first approach..? All of my entity set should have some common fields for keeping recordinfo public DateTime CreatedAt { get; set; } public int CreatedBy { get; set; } public DateTime ModifiedAt { get; set; } public int ModifiedBy { get; set; } public bool IsDeleted { get; set; } I want to keep this fields at the end of the table. Is there any possible EF configuration that i can use to config this

problem when i try printing sales invoice

◇◆丶佛笑我妖孽 提交于 2020-01-22 02:32:18
问题 private void button1_Click(object sender, EventArgs e) { hesham2020Entities2 db = new hesham2020Entities2(); string u; u = textBox1.Text.Trim(); var y = from v in db.inv_detail from s in db.invoice_head where s.invno==u select new {v.unit,v.qty,v.p_no,v.description,v.price,v.tot_price,s.invno,s.customer_id,s.inv_dat,s.po_no,s.total,s.currency}; CrystalReport6 crt = new CrystalReport6(); crt.SetDataSource(y); crv9.Refresh(); crt.SetParameterValue(0, comboBox2.SelectedItem); crt

Understanding Asp.Net Identity key points

ぃ、小莉子 提交于 2020-01-21 08:16:23
问题 I am an Asp.net developer but very much new to the Asp.net Identity framework. I have been studying the sample application and followed some tutorials too on Identity but still I am not able to grasp the concept completely. I have very firm grip over Asp.net membership but Identity seems nothing like membership. I will explain what I have done so far. I am creating a simple application in which I am following code first approach. I have created entity model for User which inherits from

How to search and load data in database by using a string keyword

天涯浪子 提交于 2020-01-17 14:35:09
问题 This is my ProgramCategories model public class ProgramCategories { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int id { get; set; } public string courseCategory { get; set; } } This is my course information model. public class CourseCategory { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ID { get; set; } [Required(ErrorMessage = "Please Select Field of Study")] [Display(Name = "Field of Study")] public string courseField { get; set; } [Required