entity-framework-4

Entity Framework Code First in class library

北战南征 提交于 2020-01-02 05:33:04
问题 I just started trying my hands on EF4 code first this morning and I created my POCO, data context and Initializer classes in a separate class library, I believe it's the regular boiler plate type code. I reference the class in an MVC3 application and set the initializer in the Global.asax. On running the app, I notice the following problems 1. No database is created anywhere (Then I add an entry in the web.config for a connection string named after the Context class, still no result) 2. When

Cascade Delete, same table, Entity Framework 4 Code First

白昼怎懂夜的黑 提交于 2020-01-02 03:42:05
问题 Hi Im currently working with .sdf database (Server Compact Version 4.0) and sql express. I'm trying to setup a cascade delete on a same table (category - sub category) but I get that I cant add relation to the same table. A foreign key constraint had and update or a delete cascade rule, and self-references a column in the same table, is not allowed What can I do about this? EDIT I'm the only one with this problem? 回答1: As your SQLException suggested, this is a limitation of SQL Server in

Using a enum with flag in an Entity Framework query

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-02 03:10:06
问题 i have a enum type like below [Flags] public enum WeekDays { Monday = 1, Tuesday = 2, Wednesday = 4, Thursday = 8, Friday = 16, Saturday = 32, Sunday = 64, } WeekDays dw = WeekDays.Friday | WeekDays.Monday | WeekDays.Saturday; int dwInt = (int)dw; var list = query.Where(f => f.FromDateTime.DayOfWeek == dwInt "??????????? what can i do there????").ToList(); 回答1: I'm going to make a guess that you weren't sure what to put in the query to filter for the days you list in the source. Given your

DbUpdateException with entities that do not expose foreign key properties

不羁岁月 提交于 2020-01-02 02:19:08
问题 I have an entity model with User and Person entities, such that each User must be associated with exactly 1 Person , and each Person can be associated zero or 1 User . User (0..1) <-------> (1) Person The association is mapped fluently. Originally I only had it declared on the Person side: private class PersonOrm : EntityTypeConfiguration<Person> { internal PersonOrm() { ToTable(typeof(Person).Name, DbSchemaName.People); // has zero or one User HasOptional(p => p.User) .WithRequired(d => d

Using a SQL Function in Entity Framework Select

大城市里の小女人 提交于 2020-01-01 18:30:13
问题 I am using the Devart EF-4 provider for PostgreSQL. In one of my db tables, I have a column called the_geom which is a PostGis Geometry type column holding a polygon. Long story short, PostGis uses its own binary format to store geometry values, so for it to be usable in my application i need to convert it to Well-Known-Binary (WKB) which is a standardized binary representation of geometry. This can be achieved quite easy in standard SQL by selecting in with select asbinary(the_geom) from

Entity Framework Logical Entity Error

眉间皱痕 提交于 2020-01-01 15:05:07
问题 I want to have a Person entity in my model. There is no corresponding table and no discriminator. I simply want it as a common base class for some other entities to share (I want to define a public partial class Person with common functionality. So, for example, I want to have: // this class has no corresponding table in the DB public partial abstract class Person { public int Id {get; set;} public string FirstName {get; set;} public string LastName {get; set;} public string DisplayName { get

Entity Framework POCO objects

一笑奈何 提交于 2020-01-01 15:00:09
问题 I'm struggling with understanding Entity Framework and POCO objects. Here's what I'm trying to achieve. 1) Separate the DAL from the Business Layer by having my business layer use an interface to my DAL. Maybe use Unity to create my context. 2) Use Entity Framework inside my DAL. I have a Domain model with objects that reside in my business layer. I also have a database full of tables that doesn't really represent my domain model. I setup Entity Framework and generated POCO objects by using

EntityConnection and Opened SqlConnection

不问归期 提交于 2020-01-01 12:43:09
问题 I've a question about EntityFramework with CodeFirst approach. Based on EntityConnection source code and documentation I can't create it with already opened SqlConnection. It requires that is should be closed. We have some different DB data layers(nHibernate,etc), and it would be good, if we can reuse the same SqlConnection between them. But seems, that EntityFramework doesn't allow to do this. I can pass closed SqlConnection to DbContext, but it isn't good for me to close connection for each

Entity Framework DateTime column - GetDate() value Insertion

[亡魂溺海] 提交于 2020-01-01 09:21:46
问题 I have a table with DateCreated and DateUpdated columns and using Entity Framework to insert/update values to the database. I need the DateCreated column to get the SQL Server's GetDate() value on insertion only. DateUpdated column value should always get updated with current GetDate() value on insertion and update both. For the DateCreated column, I've set StoreGeneratedPattern="Computed" and on SQL Server table I've set default value of the column to be GetDate(), which works nicely as

What is the most efficient way to do comparisons involving many-many relationships with LINQ in EF 4.1?

99封情书 提交于 2020-01-01 09:16:14
问题 In my database I have the following tables: Person Post InterestTag Many-Many relationships exist between Person-InterestTag and Post-InterestTag I need to perform a linq query in EF 4.1 to pull back any post that contains at least one interest tag that matches at least one interest tag related to the given user. Example A person has the following interests: Cars Sports Fitness I need to return any Post that is related to either cars, sports, or fitness. What is the most efficient way to