entity-framework-4.1

How can I localize the Entity Framework build-in validation messages/exceptions?

会有一股神秘感。 提交于 2019-12-12 16:31:25
问题 Beside the annotation-based validation mechanism EF provides the so-called "Facets". Meaning on a string property you could have a "Max Length" Facet (through the EF model configuration) where you specify a max-length of 80 chars. Most often this is done automatically by EF when you use a database first approach. If now the property contains more than the specified number of chars, EF will throw a DbEntityValidationResult with the message [PropName]: The field [PropName] must be a string or

Entity Framework validation failed when updating a class with virtual properties

别等时光非礼了梦想. 提交于 2019-12-12 16:04:34
问题 I'm having problems updating a property of a class when the class contains virtual properties. Here is my code public class Policy { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public long id { get; set; } [UIHint("Company"), Required] public virtual Company company { get; set; } [UIHint("Productor"), Required] public virtual Productor productor { get; set; } [MaxLength(1000)] public string comments { get; set; } } public class Company { [Key] [DatabaseGenerated

EntityTypeConfiguration - What is a clean method to test mapping against the database?

心已入冬 提交于 2019-12-12 15:50:17
问题 Background: My company's current structure is using Plinqo/Linq to Sql to create "data access objects", and then use a custom set of CodeSmith templates to build "business objects". To make a very long story short, these two sets of objects are very tightly coupled and, with Linq to SQL, lead to pretty ugly workarounds. The Plinqo templates do a direct 1:1 mapping of table to class after generating the dbml. This leads to some comfort in that if the database changes, there is a compile-time

Using StoreGeneratedPattern.Identity with database-trigger-generated primarykey values not possible?

血红的双手。 提交于 2019-12-12 15:43:30
问题 This question is related to another question i asked here ( Entity Framework 4.2 - How to realize TPT-Inheritance with Database-generated Primarykey Value? ) and should simply clarify, if my assumptions, regarding the problem stated in the topic, are right or not. The Problem (in detail): I want to use EF (4.1) to access a database, that already exists the database has some restrictions regarding the generation of primary key values for its tables (there is a UDF that takes a tablename and

EF Code First Existing database

…衆ロ難τιáo~ 提交于 2019-12-12 12:26:20
问题 Using EF 4.1 Code first I wanted to stop EF creating database from Models. As I understand if you pass Connectionstring name it will use existing database from that connection string. However if the database does not exists then it will create database will all the tables form the model. <connectionStrings> <add name="DiaryContext" connectionString="Data Source=.;Initial Catalog=Diary;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/> public MyDiaryContext() : base("name

ADO EF Code First Generic Intermediate Class Inheritance mapping

我的梦境 提交于 2019-12-12 10:44:29
问题 I've got the following requirement that works well in the OO space but I can't seem to get it to map back to the DB using ADO EF code first. I have numrous products each will have different aspects (attributes but not in the sense of code attributes). For instance ring would have aspects such as mineral type = gold etc whilst a diamond would have an aspec of clarity = VVSI1. As you can see the products very greatly in thier composition and I want a dynamic way of growing my system. As such I

Entity Framework code first with T4 template

柔情痞子 提交于 2019-12-12 10:43:22
问题 I am going to create code-first view by using a T4 template like the below mentioned article says: Article here But it's causing an run time exception like below. Why's that? My connection string is configured properly in App.config . My application is N-Tier based .So That DbContext driven class is in Data Layer . This is my connection String : <add name="PawLoyalty" connectionString="Server=.;database=PawLoyalty;Trusted_connection=true;pooling=true;MultipleActiveResultSets=True"

EF 4.1 CodeFirst with Guid (not generated by DB/Store) as PK

痴心易碎 提交于 2019-12-12 10:38:58
问题 I'd like to create a model with a 'client generated' GUID as the primary key. I want the Guid to be auto-generated, but NOT on the DB, so I know the ID before I persist it, important for my domain model. How do I setup: class MyEntity { public Guid ID { get; set; } } So I can do... var newEntity = new MyEntity(); transmitIDBeforePersisting(newEntity.ID); context.MyEntities.Add(newEntity); context.SaveChanges() How can I setup MyEntity.ID so it is auto-generated when I call new, but still

Attach entity in modified state without marking all properties dirty

允我心安 提交于 2019-12-12 10:34:02
问题 I'm trying to figure out how to mark specific properties of a detached entity as modified. If I do the following, it will mark all properties modified and the generated sql will update all columns. /// <summary> /// Sets the entity in the modified state. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity">The entity.</param> void IDbContext.Modified<T>(T entity) { DbEntityEntry<T> entry = Entry(entity); if (entry.State == EntityState.Modified) { // if the state is

Implement WCF Data Service using the Repository Pattern

六眼飞鱼酱① 提交于 2019-12-12 08:57:20
问题 We are using the repository pattern in our ASP.NET MVC 3 application. This means that, although we use EF 4.1 Code First to access the data in the backend, all MVC controllers do that via a generic repository class rather than directly over the DbContext subclass. Simplified code snippet: public class MyEntityContext : DbContext, IMyEntityContext { public IDbSet MyEntities { get; set; } ... } public class MyEntityRepository : IMyEntityRepository { private IMyEntityContext _context; public