ef-code-first

Entity Framework Column Type for Base64 String

[亡魂溺海] 提交于 2019-12-13 18:18:43
问题 I am using code first Entity Framework and four of my columns are a base64 representation of an image and are of type string. Initially, I was allowing EF to store these as the default nvarchar(max). I learned today that nvarchar(max) is twice the size of what the data actually is, when dealing with images this difference is tremendous. I've tried to use varchar, but it appears the max length on that is 8000 which is too small for a base64 image. I've also tried text, but that does not appear

EF: 1:1 relationship independent association

北慕城南 提交于 2019-12-13 17:45:33
问题 I'm trying to create a simple 1:1 relationship with EF code first. Example: A person always owns a single car and the car always belongs to a single person. Person: public class Person { public Guid Id { get; set; } public string Name { get; set; } public Car Car { get; set; } } // PersonEntityTypeConfiguration HasKey(k => k.Id); Property(p => p.Name).IsOptional(); HasRequired(n => n.Car).WithRequiredPrincipal().WillCascadeOnDelete(true); Car: public class Car { public Guid Id { get; set; }

Entity Framework Code First Update a Single Property of a Complex Type

怎甘沉沦 提交于 2019-12-13 16:45:17
问题 I am having a weird behavior. I want to update a single property of a complex type. When I specify properties to be updated with IsModified (some property are to true and some to false) I have nothing updated. If I specify no property of the complex type, every field of the complex property are updated. public class MyEntity { public MyComplexClass Property1 { get; set; } } //... The code below doesn't work, in fact it update nothing var entityLocal = this.Set<MyEntity>().Local

Entity Framework 1-1 relationship is not persisting data to the database

别来无恙 提交于 2019-12-13 16:27:26
问题 I've got a table FeeMetadata with a PK FeeID BIGINT IDENTITY(1,1) NOT NULL This table contains two 1-1 relationships. One to PFD.Fees , and one to SoaCourt.Fees via the FeeID column (same name in all three tables, only the metadata table is marked as IDENTITY, the other two tables this column is PK but NOT identity) Here's the code for the EF classes: Namespace PFD <Table("FeeMetadata", Schema:="PFD")> Public Class FeeMetadata Public Sub New() MyBase.New() End Sub Public Sub New(ByVal tFee As

EF Code first, seeding and deployment

☆樱花仙子☆ 提交于 2019-12-13 16:22:42
问题 I want to seed our initial database with users (for a ASP.NET web app) on install. For some reason its not working correctly. Ive read loads of topics that mostly say run update-database which works great from the console but how does this work in a production environment? As an attempt to circumvent this I have ended up with the following code - what am I missing here? Global.asax.cs::Application_Start() try { initializationError = null; WebSecurity.InitializeDatabaseConnection(

Is using a (sequential) GUID the only viable alternative to a database generated ID?

与世无争的帅哥 提交于 2019-12-13 16:09:41
问题 We are migrating our MS-Access database to SQL Server Compact 4.0 using the Entity Framework 5 Code First approach. We found that using Database generated Integer ID's is very slow and to make it worse, the delay increases exponentially with the size of the database. This makes using an Identity column impossible and it seems there is a bad implementation of this feature in SQL Server Compact 4.0 paired with the Entity Framework. So, we ran some tests and found that using a client side

EntityFramework Code First inheritance with custom discriminator

∥☆過路亽.° 提交于 2019-12-13 16:06:17
问题 I'm trying to map the following inheritance in EntityFramework Code First public class Member { public string ProjectName { get; set; } public string AssemblyName { get; set; } public string NamespaceName { get; set; } public string TypeName { get; set; } public string Signature { get; set; } public string DisplayName { get; set; } public MemberType Type { get; set; } public string Summary { get; set; } public bool IsStatic { get; set; } public bool IsInherited { get; set; } //public virtual

Entity Framework Filtered Navigation Properties

空扰寡人 提交于 2019-12-13 15:35:24
问题 Is there a way to set a filter on a navigation property using EF6/code first? I want to achieve something similar to the below, where Farm.Pigs returns a collection of animals whose type is equal to pig (but without loading the whole collection from the database first - and not storing them in a separate table). Is this possible? public class Farm { public int Id { get; set; } public virtual ICollection<Animal> Pigs { get; set; } public virtual ICollection<Animal> Cows { get; set; } } public

Entity Framework 4.1 Code-First approach to realize many-to-many relation over Domain-Services

♀尐吖头ヾ 提交于 2019-12-13 15:14:10
问题 I had some problems while creating a database model using the newest Entity Framework and Code-First (see Entity Framework 4.1 Code First approach to create many-to-many relation for details). Meanwhile I've figured out that the problem isn't the Entity Framework itself any more, but using it along with WCF RIA DomainServices. For the sake of completeness - that's my relevant Code-First code: // // Models // public class Author { public Author() { this.Books = new Collection<Book>(); }

Using EF6 Store Functions for Entity Framework code-first, can I return a custom type?

送分小仙女□ 提交于 2019-12-13 12:09:14
问题 I have an entity class: public class SomeClass { public int Id { get; set; } public int Value { get; set; } public string Name { get; set; } } using the EF6 Store Functions for Entity Framework code-first by Moozzyk, I see example code that maps a function to an entity type. However, when using a type that isn't already mapped as an entity, I receive an exception saying the type is not a valid entity type. Example: [DbFunction("MyContext", "GetValueSum")] public IQueryable<SomeClassSummary>