ef4-code-only

How can I add an Image type to an EF4 Code First Entity?

我只是一个虾纸丫 提交于 2019-12-06 01:52:21
问题 How can I add an Image type to an EF4 Code First Entity? I need to add a column for thumbnail images. public Image Thumbnail { get; set; } Thanks! 回答1: Images are represented as binary in EF 4 http://thedatafarm.com/blog/data-access/sql-server-2008-data-types-and-entity-framework-4/ You will need to do something like this public Binary Thumbnail {get; set} Then convert the image to binary This reference will help you with the image to binary conversion http://www.dotnetspider.com/resources

EF4 Code only mapping inheritance

天大地大妈咪最大 提交于 2019-12-04 14:20:05
问题 I've got the following model and I want ShiftRequest and MissionRequest to have a single table in the DB. public class RequestBase { public int Id { get; set; } public DateTime? RequestDate { get; set; } public int UserId { get; set; } public virtual ICollection<Notification> Notifications { get; set; } } public class ShiftRequest : RequestBase { public virtual Column Column { get; set; } } public class MissionRequest : RequestBase { public virtual Mission Mission { get; set; } } I've tried

XML data type in EF 4.1 Code First

ε祈祈猫儿з 提交于 2019-12-04 09:15:08
问题 I would like to use SQL Server xml type as a column type for an entity class. According to this thread it's possible to map such a column to string type: public class XmlEntity { public int Id { get; set; } [Column(TypeName="xml")] public string XmlValue { get; set; } } The table is correctly generated in the datebase by this definition. New XmlEntity objects are also can be created. But then I try to get some entity from the database: var entity = db.XmlEntities.Where(e => e.Id == 1)

How can I add an Image type to an EF4 Code First Entity?

ぃ、小莉子 提交于 2019-12-04 06:38:00
How can I add an Image type to an EF4 Code First Entity? I need to add a column for thumbnail images. public Image Thumbnail { get; set; } Thanks! Images are represented as binary in EF 4 http://thedatafarm.com/blog/data-access/sql-server-2008-data-types-and-entity-framework-4/ You will need to do something like this public Binary Thumbnail {get; set} Then convert the image to binary This reference will help you with the image to binary conversion http://www.dotnetspider.com/resources/6150-Convert-Image-binary-format.aspx public System.Data.Linq.Binary Thumbnail {get; set} For those wondering

EF4 CTP5 self-referencing hierarchical entity mapping

扶醉桌前 提交于 2019-12-03 17:08:21
Okay, this should be really easy, but I've been tearing my hair out. Here's my POCO (which has to do with machine parts, so a part can be contained within a parent part): public class Part { public int ID { get; set; } public string Name { get; set; } public Part ParentPart { get; set; } } When the database table is created, the column names are "ID", "Name", and "PartID". How do I change the name of that last column to "ParentPartID"? Basically, you want to rename the foreign key in an Independent Association and this is the fluent API code that will do it: protected override void

EF4 Code only mapping inheritance

五迷三道 提交于 2019-12-03 10:00:53
I've got the following model and I want ShiftRequest and MissionRequest to have a single table in the DB. public class RequestBase { public int Id { get; set; } public DateTime? RequestDate { get; set; } public int UserId { get; set; } public virtual ICollection<Notification> Notifications { get; set; } } public class ShiftRequest : RequestBase { public virtual Column Column { get; set; } } public class MissionRequest : RequestBase { public virtual Mission Mission { get; set; } } I've tried to do it in the override void OnModelCreating(ModelBuilder modelBuilder) method but only one

Entity Framework 4: Code First - Creating db in another schema? MapSingleType?

回眸只為那壹抹淺笑 提交于 2019-11-30 06:29:53
I have a database and i using 2 different schemas. Schemas are like namespaces (correct me if i am wrong). This way i have 1 db and currently 2 schemas... so the tables in 1 schema can be named the same as the tables in the other schema because they are in separate schemas. How do i get EF Code first to talk to a different schema and not the default schema? Is it somethign to do with MapSingleType and overriding a method or can i do something else? ANy help really appreciated. Devart You can implement the following convention: public class DefaultSchemaConvention : IConfigurationConvention

using Guid as PK with EF4 Code First

穿精又带淫゛_ 提交于 2019-11-30 06:20:33
问题 I have this class and table: public class Foo { public Guid Id {get;set;} public string Name {get;set;} } create table Foo ( id uniqueidentifier primary KEY DEFAULT (newsequentialid()), name nvarchar(255) ) the problem is that when i try to save new foo the first one goes with the 0000-000-00 ... id and the second also, so I get constraint exception anybody knows a fix ? 回答1: Have you set Identity StoreGeneratedPattern? You can do it in the OnModelCreating method: modelBuilder.Entity<Foo>()

DbContext SaveChanges Order of Statement Execution

…衆ロ難τιáo~ 提交于 2019-11-29 13:16:53
I have a table that has a unique index on a table with an Ordinal column. So for example the table will have the following columns: TableId, ID1, ID2, Ordinal The unique index is across the columns ID1, ID2, Ordinal. The problem I have is that when deleting a record from the database I then resequence the ordinals so that they are sequential again. My delete function will look like this: public void Delete(int id) { var tableObject = Context.TableObject.Find(id); Context.TableObject.Remove(tableObject); ResequenceOrdinalsAfterDelete(tableObject); } The issue is that when I call Context

using Guid as PK with EF4 Code First

末鹿安然 提交于 2019-11-28 17:27:04
I have this class and table: public class Foo { public Guid Id {get;set;} public string Name {get;set;} } create table Foo ( id uniqueidentifier primary KEY DEFAULT (newsequentialid()), name nvarchar(255) ) the problem is that when i try to save new foo the first one goes with the 0000-000-00 ... id and the second also, so I get constraint exception anybody knows a fix ? Devart Have you set Identity StoreGeneratedPattern? You can do it in the OnModelCreating method: modelBuilder.Entity<Foo>().Property(o => o.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); or using the