entity-framework-4.1

Cannot Insert custom value into identity column - Entity Framework

大兔子大兔子 提交于 2019-12-07 06:47:51
问题 I am trying to switch the identity off to insert my own value, steps I followed changed the property StoredGeneratedPattern value to None for the identity column changed the property StoredGeneratedPattern value to None in EDMX file by opening in xml format Tried using the below code using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { int k = Context.ExecuteStoreCommand("SET IDENTITY_INSERT dbo.client ON"); Context.ClientInfoes.Add(testclient); result =

How Do I Disable Lazy Loading, Entity Framework 4.1 using Code Migrations Configuration

拜拜、爱过 提交于 2019-12-07 06:40:25
问题 This is the code im using to configure the database: internal sealed class Configuration : DbMigrationsConfiguration<DataStore> { public Configuration() { AutomaticMigrationsEnabled = true; SetSqlGenerator("System.Data.SqlServerCe.4.0", new SqlCeModelColumnBugWorkaroundProvider()); } protected override void OnSeed(DbContext context) { context.Configuration.LazyLoadingEnabled = false; new SeedData(context as DataStore); } public static void DoDatabaseInitialisation() { var setting =

Entity Framework Code First - How to ignore a column when saving

让人想犯罪 __ 提交于 2019-12-07 06:36:41
问题 I have a class called Client mapped to a database table using Entity Framework code first. The table has a computed field that I need available in my Client class, but I understand that it won't be possible to write to this field. Is there a way of configuring Entity Framework to ignore the property when saving, but include the property when reading? I have tried using the Ignore method in my configuration class, or using the [NotMapped] attribute, but these prevent the property from being

Execute StoredProcedure in CodeFirst 4.1

不羁岁月 提交于 2019-12-07 05:55:44
问题 I understand stored procedures mapping is not supported by my understanding is that I should be able to call stored procedures. I have quite a few complex stored procedures and with the designer I could create a complex type and I was all good. Now in code first let's suppose I have the following stored procedure, just put together something silly to give an idea. I want to return a student with 1 address. In code I have A Student and Address Entity. But no StudentAddressEntity as it's a link

One to Many with a join table and an optional relationship in Entity Framework 4.1 Fluent API

雨燕双飞 提交于 2019-12-07 04:56:27
问题 Again with a legacy database that cannot be changed and using Entity Framework 4.1 with the Fluent API to read data only. public class Client { [Key] public int ClientID { get; set; } public string Name { get; set ;} public virtual ICollection<Phone> Phones { get; set; } } public class Phone { [Key] public int PhoneID { get; set; } public string Number { get; set; } public virtual Client Client { get; set; } } public class ClientPhone { [Key] [Column(Order=0)] public int ClientID { get; set;

Entity Framework Change Tracking API and reference entries

非 Y 不嫁゛ 提交于 2019-12-07 01:36:55
问题 Looking to write generic Audit code on my DbContext subclass. foreach (var entry in this.ChangeTracker.Entries<MyClass>()) { if (entry.State == EntityState.Modified) { var entityProperties = entry.Entity.GetType().GetProperties(); foreach (var entityProperty in entityProperties) { DbMemberEntry propertyEntry = entry.Member(property.Name); if (propertyEntry is DbPropertyEntry) { // IsModified available } else if (propertyEntry is DbReferenceEntry) { // IsModified not available } } } } 1) If I

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

时间秒杀一切 提交于 2019-12-07 01:31:16
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 this error? Connectionstring <connectionStrings> <add name="DataContext" connectionString="Data Source

literal or constant as part of composite key in EF code first

此生再无相见时 提交于 2019-12-07 01:24:28
问题 I am relatively new to the Code First approach to Entity Framework. I have used the Database First approach for a while now, but the Code First seems to be a better fit for the application I am currently developing. I am working with an existing MS SQL database, and I am not allowed to make any changes whatsoever to the database. The reason why I am using Code First is because the Fluent API allows me to dynamically assign a table name to a class. That said, I have a predicament where I need

Is it possible to create User-Defined Data Types when using EF 4.1 Code First?

我是研究僧i 提交于 2019-12-07 00:43:30
When using EF 4.1 Code First, is it possible to create User-Defined Data Types for your schema? Simple answer is no. Longer answer: Current EF implementation leads to multiple issues when trying to use user defined types: The type must be defined prior to its usage in table's DDL definition. Because of that the type cannot be defined in Seed method of database initializer (as often used for other database constructs like triggers or indexes). To make this work you must create whole new initializer by implementing IDatabaseInitializer and separate database creation and table creation because

Exclude column from being updateable in Entity Framework 4.1 Code First

不羁岁月 提交于 2019-12-06 22:26:20
问题 Does anyone know if we can exclude column from being updated in Entity Framework 4.1 Code First? For example I have 'CreatedOn' field that I don't want to included when doing edit/updates. Is this possible, i.e. selectively excluding field from update operation in EF Code First 4.1? 回答1: If you are working with attached entities you EF will generate updates only for fields which have changed. If you are working with detached entities you must manually say EF what has changed. If you call this