entity-framework-4.1

Entity framework strings using greater than operator

南笙酒味 提交于 2019-12-08 15:50:05
问题 How do I make this query work like it does in sql? In sql I can use < and > operators on strings. I've been googling this for about 20 minutes and have found no solution yet. I cannot convert r.ExemptionCode to an integer as it may have values like '91A,9AA,ZZZ,Z01' from r in results where (r.ExemptionCode > "900" || r.ExemptionCode == "701" || r.ExemptionCode == "702" || r.ExemptionCode == "721" || r.ExemptionCode == "724") select r 回答1: Try this : from r in results where (r.ExemptionCode

EF 4.1 Referential integrity error

99封情书 提交于 2019-12-08 15:27:13
问题 I have the following classes: public class Person { [Key] public Guid Id { get; set; } [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } [Required] public string Email { get; set; } public virtual Survey Survey { get; set; } } public class Survey { [Key] public Guid Id { get; set; } public bool IsFinished { get; set; } public virtual ICollection<UserAnswer> UserAnswers { get; set; } public virtual Person Person { get; set; } } public class

Entity Framework 4.1 Code First Freeze

南楼画角 提交于 2019-12-08 09:59:31
I'm having trouble getting EF 4.1 working on my computer. It seems to be some problem with my database settings. I was trying out this simple walkthrough: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx But when it reaches db.Categories.Add(food); it just freeze. I have a normal SQL Server 2008 R2 installed, not SQL Express. There also seems to be some problems with creating .mdf files instead of a direct connection to the localhost SQL server. I've also tried adding an entity model with a database connection, but this does not seem to work. Do anyone have

Delete Many to Many relationship using Entity Framework

蹲街弑〆低调 提交于 2019-12-08 08:16:15
问题 I've three tables Student (studID, fullName, gender...), Enroll (studID, courseID, date) and Course (courseID,courseName, ...). I used the code below to delete all records from Enroll table with studID 001 where there are about three courses the student signed for. However, it only deletes one record. using(var context = new DBEntities()) { var _stud = (from s in context.Students where s.studID == "001" select s).FirstOrDefault(); var _course = _stud.Courses.FirstOrDefault(); _course.Students

Entity Framework 4.2 - How to realize TPT-Inheritance with Database-generated Primarykey Value?

淺唱寂寞╮ 提交于 2019-12-08 07:53:27
问题 I want to use the EF (4.2) in the following scenario: There exists a database already (so I chose the database-first approach) and it is a SQL Anywhere DB. I want to use persistence-ignorant business objects, so I use the DbContext Template to generate POCO classes from the EDM. There is one simple inheritance hierarchy among my entities: an abstract base entity and two concrete derived entities. In the database there is one table for each type of the inheritance hierarchy (Table-Per-Type

Multiple Inheritance issue with EF 4.1

会有一股神秘感。 提交于 2019-12-08 07:34:12
问题 I am not sure what I am doing wrong here, but I am having an issue with multiple inheritance and building my model. I get the error " The property 'Id' is not a declared property on type... ". Everything worked fine before I added the ContextEntity class and I had a TPC model. Each (non abstract)derived entity had it's own ID and own table. The other classes always existed and my mappings worked fine. Here are my classes: public abstract class Entity { public virtual Guid Id { get; set; }

Exception : The provider did not return a ProviderManifestToken string-Entityframework

元气小坏坏 提交于 2019-12-08 07:02:53
问题 I have write a method for inserting some data to the db using Entity framework like below which is called as a wcf service bool status=false; MyDataContext dc = new MyDataContext(); var getData = dc.Register.FirstOrDefault(x => x.DeviceId == deviceId.Trim()); if (getData != null) { status = true; } return status; In local it insert successfully. But after publishing i try to insert again.At that time i got exception The provider did not return a ProviderManifestToken string How can i resolve

Are navigation properties read each time they are accessed? (EF4.1)

此生再无相见时 提交于 2019-12-08 06:37:58
问题 I am using EF 4.1, with POCOs which are lazy loaded. Some sample queries that I run: var discountsCount = product.Discounts.Count(); var currentDiscountsCount = product.Discounts.Count(d=>d.IsCurrent); var expiredDiscountsCount = product.Discounts.Count(d=>d.IsExpired); What I'd like to know, is whether my queries make sense, or are poorly performant: Am I hitting the database each time, or will the results come from cached data in the DbContext? Is it okay to access the navigation properties

Entity Framework failing to retrieve data due to exceptions

限于喜欢 提交于 2019-12-08 06:24:36
问题 Here are my two POCOs: [Table("Movie", Schema= "dbo")] public class Movie: BaseClass { public string TitleName { get; set; } public virtual ICollection<Actor> Actor{ get; set; } } [Table("Actor", Schema="dbo")] public class Actor: BaseClass { public string FirstName { get; set; } public string LastName { get; set; } public DateTime? BirthDate { get; set; } } Base class is just a class that has a property int id. In the database, there's an Movie table and an Actor table with a MovieActor

DDD Modules and EF Code First

耗尽温柔 提交于 2019-12-08 06:04:04
问题 I am trying to follow Domain Driven Design using VS.NET 2012 & EF5. I might have more than 250 Tables (and similar number of POCO Entity classes). If I decide to keep policy/rules/validation, all in one project/.dll, it is gonna be very hefty .dll and multiple developers working on same domain project will make it difficult to work together. To keep Domain Layer Manageable: I divided it into different Modules. Each module have it's own Domain project & Service Layer. All the modules will have