entity-framework-4.1

An overflow occurred while converting to datetime using EF4

假装没事ソ 提交于 2019-11-28 21:14:17
I have a windows application working with a SQL Compact 4.0 database, using EF 4.1 and code-first approach. I cannot save an object to the database since I'm getting an exception, with inner exception "An overflow occurred while converting to datetime" when trying to save the type Quotation: public class Quotation { public int ID { get; set; } public string Name { get; set; } public DateTime DateCreated { get; set; } public ContactPerson ContactPersonAssigned { get; set; } public string OurReference { get; set; } public string QuotationDataString { get; set; } } I read that this error can be

Multiple foreign keys pointing to same table in Entity Framework 4.1 code first

走远了吗. 提交于 2019-11-28 20:33:47
I'm stuck at trying to write the Entity Framework 4.1 code first model for the following DB relationship. Here is a visual of the relationship. dbo.[Companies] can have either Seller or Debtor as Company Types. dbo.[SellerDebtors] defines the connection a Seller Company has with a Debtor Company. The code i've written is based on my original EF 4.0 POCO model code. This is what I've come up with - This code does not work. public class SellerDebtor { public int SellerDebtorId { get; set; } public int DebtorCompanyId { get; set; } public int SellerCompanyId { get; set; } public Company

Why does EF 4.1 not support complex queries as well as linq-to-sql?

和自甴很熟 提交于 2019-11-28 19:50:58
I am in the process of converting our internal web application from Linq-To-Sql to EF CodeFirst from an existing database. I have been getting annoyed with Linq-To-Sql's limitations more and more lately, and having to update the edmx after updating a very intertwined database table finally frustrated me enough to switch to EF. However, I am encountering several situations where using linq with Linq-To-Sql is more powerful than the latest Entity Framework, and I am wondering if anyone knows the reasoning for it? Most of this seems to deal with transformations. For example, the following query

EF 4.1, Code-First: Is there an easy way to remove ALL conventions?

一个人想着一个人 提交于 2019-11-28 19:38:04
We can remove single conventions this way: modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); modelBuilder.Conventions.Remove<ConcurrencyCheckAttributeConvention>(); // and 31 conventions more But I miss something like modelBuilder.Conventions.RemoveAll() . Is there an easy way to remove ALL of them? (I am even not sure if I really want to remove all conventions finally. But with my growing object model I have difficulties to distinguish clearly which parts of the mapping to the DB come from conventions and which parts I have indeed configured explicitely in the Fluent API. I

Self referencing / parent-child relationship in Entity Framework

喜你入骨 提交于 2019-11-28 18:39:59
I read quite a number of posts of programmers that run into the Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values -exception when using a self-referencing relationship in Entity Framework. I am trying to get a parent-child relationship to work: public class Category { public int CategoryId { get; set; } public string Name { get; set; } public int ParentId { get; set; } public Category Parent { get; set; } public List<Category> Children { get; set; } } This is the configuration I

Entity Framework/MVC3: temporarily disable validation

自闭症网瘾萝莉.ら 提交于 2019-11-28 18:13:39
I am using EF Code First. I heavily use code annotations to specify how the data (model) should be validated. However, often I just need validation at UI layer and be able to suppress validation when I save certain data to the database in the code. However, once I specified validation rules, they are applied everywhere -- on the UI, on the database, on the data access layer. Can I temporarily disable model validation at EF layer so I can save the data using SaveChanges() without getting validation exceptions? You just need to set Configuration.ValidateOnSaveEnabled = false in your context

Entity Framework 4.1 Code First Self-Referencing One-to-Many and Many-to-Many Associations

女生的网名这么多〃 提交于 2019-11-28 17:57:47
I have a User that can have collection of users he likes... Another user can have collection of users he likes.... If User A likes User B and if User B likes User A, then they get to hang out. I need to send each other their contact info. How do we represent such a model in Entity Framework Code First? public class User { public int UserId { get; set; } public int? UserLikeId { get; set; } public virtual UserLike UserLike { get; set; } } public class UserLike { public int UserLikeId { get; set; } public int UserId { get; set; } public virtual User User { get; set; } public virtual ICollection

Entity Framework creates foreign key objects instead of using those that are already available

回眸只為那壹抹淺笑 提交于 2019-11-28 16:46:30
问题 my current project is based on Entity Framwork code-first. I have three types: Task, TaskType and Module. public class Task { public int ID { get; set; } public Module Module { get; set; } public TaskType Type { get; set; } } public class TaskType { public int ID { get; set; } public string Name { get; set; } } public class Module { public int ID { get; set; } public string Name { get; set; } } There are foreign key relations defined inside the table for the Task-type. My problem is that when

Entity Framework Code-first default data in database

我们两清 提交于 2019-11-28 15:47:51
How do I handle situations in which I need pre-existing data before the app is started or right after the database is generated. For example, I have a list of countries in which I'd like to load into the database after code-first generates it. How do I do this? App is structured as follows: Repository > Service > WebMVC The xml is in the WebMVC project. Damb You create custom initializer, which inherits from DropCreateDatabaseIfModelChanges or DropCreateDatabaseAlways interface. Like: public class EntitiesContextInitializer : DropCreateDatabaseIfModelChanges<-YourDbContext-> And then you

EF ICollection Vs List Vs IEnumerable Vs IQueryable

久未见 提交于 2019-11-28 15:23:19
so, my EF model has relationships and according to what I have seen in examples, those relationships should be done with virtual properties of ICollection. Example: public class Task { public int Id { get; set; } public string Description { get; set; } public virtual ICollection<SubTask> { get; set; } } I read somewhere that I should use IEnumerable to prevent deferred execution, is that correct? It means that if my DAL methods return IEnumerable, still of IQueryable, the SQL will be executed at that moment, and not at the moment when I call .TOList in the web page. So, what is the best