entity-framework-4.1

make byte[] property load lazy

我怕爱的太早我们不能终老 提交于 2019-12-01 10:26:59
I'm using EF4 Code First and I have a property: public byte[] Bytes {get;set;} can I make this property load lazily ( only when it's needed) ? Table spliting works in EF 4.1 RC: public class Item { public int Id { get; set; } ... public virtual ItemDetail ItemDetail { get; set; } } public class ItemDetail { public int Id { get; set; } public byte[] Bytes { get; set; } } public class Context : DbContext { public DbSet<Item> Items { get; set; } public DbSet<ItemDetail> ItemDetails { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating

How can i made a pivot for this

丶灬走出姿态 提交于 2019-12-01 09:39:03
问题 I have linq that return my data in this format Servicio2 | Indicador | Accion1 Servicio2 | Indicador | Accion2 Servicio1 | Indicador1 | Accion1 Servicio1 | Indicador1 | Accion2 Is there a way to transform the output to this Servicio2 | Indicador | Accion1 , Accion2 Servicio1 | Indicador1 | Accion`, Accion2 Based on this linq from A in db.IndicadorServicioAccion .Include("Accion") .Include("IndicadorServicio") .Include(i => i.IndicadorServicio.Indicador) where A.Usuario.IDUsuario == id && A

Executing a update/insert stored procedure with entity framework 4.1?

荒凉一梦 提交于 2019-12-01 09:28:14
I tried to call a stored procedure from entity framework 4.1 (mvc 3 web application). Its not throwing an exception but the insert/update is not happening? When I manually executed the stored proc it works. CREATE PROCEDURE [dbo].[SP_AddUpdateResponse] @QuestionID int, @UserID int, @AnswerValue nvarchar(2000), @ReviewID int AS MERGE [dbo].[Responses] AS [Target] USING (SELECT @QuestionID, @UserID, @AnswerValue, @ReviewID) AS [Source] ([QuestionID], [UserID], [AnswerValue], [ReviewID] ) ON [Target].[QuestionID] = [Source].[QuestionID] AND [Target].[ReviewID] = [Source].[ReviewID] WHEN MATCHED

Updating Foreign key associations in Entity Framework 4.1 Code-First

只愿长相守 提交于 2019-12-01 08:49:34
I have come to a conclusion that I should define both Independent Association and Foreign Key Association in My Code-First design. e.g: public class Book { public int ID {get; set;} public int AuthorID {get; set;} [ForeignKey("AuthorID")] public Author Author {get; set;} } With the above definition, do I have to update AuthorID when I want to change the book's author, Or just using the below line is enough? myBook.Author = author; Am I going to get a null exception on the above line if that is the first time I'm defining an author for the book? (Does EF initialize book's author automatically

Is possible to create a database (Sql Server compact) on a given path if we use Entity framework with code-first approach?

泪湿孤枕 提交于 2019-12-01 08:00:36
I'm a bit confused about Entity framework, I would like to use code-first approach; infact I would like to write how my database tables are composed through class definition. The main problem is that I need to create a database (or open it) by choosing dinamically it's path (the user can choose what database to open and can create new one when he wants). I've chosen Sql server compact to achieve this, however I still don't understand how to use code-first approach for this situation because I don't understand how to choose where database should be created with code-first approach, if is

Switch connection strings based on environment with EF 4.1/DbContext

眉间皱痕 提交于 2019-12-01 07:31:33
I have seen several posts about this but have not been able to create a usable solution from the responses. Perhaps due to a lack of understanding. The hosting provided requires that an identical code base be used on staging and production, including connection string. How do I switch the connection string for DbContext? I understand I can do something like this: public FooEntities() : base("ApplicationServices") { } But this is not dynamic - it merely sets it at runtime. So how would I actually CHOOSE the connection string at runtime? Yes public FooEntities() : base("ApplicationServices") { }

EF4.1: Possible to have zero-or-one to zero-or-one (0..1 to 0..1) relationship?

旧时模样 提交于 2019-12-01 07:17:00
问题 .NET 4.0 with SQL Server 2008 R2. I am trying to represent a 0..1 to 0..1 relationship and I keep getting the following error: Error 113: Multiplicity conflicts with the referential constraint in Role '{0}' in relationship '{1}'. Because all of the properties in Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'. I get this message even when the properties in the dependent entity are nullable. Is it possible to represent this relationship in Entity Framework? An

Generate POCO classes from model using T4 templates vs. EF4.1 simplified API Model First approach

╄→гoц情女王★ 提交于 2019-12-01 06:58:07
问题 I have model created with visual designer. Now I want to have POCO classes generated from it. In another question of mine, EF4.1 simplified API Model First approach was suggested to me. Before I was also thinking about T4 templates. What are the limitation of EF4.1 simplified API Model First comparing to using T4 templates to generate POCO classes ? What are advantages to of EF4.1 approach if any (besides it is supposed to be simpler to use)? My decision now will be very hard to undone as I

make byte[] property load lazy

ε祈祈猫儿з 提交于 2019-12-01 06:56:03
问题 I'm using EF4 Code First and I have a property: public byte[] Bytes {get;set;} can I make this property load lazily ( only when it's needed) ? 回答1: Table spliting works in EF 4.1 RC: public class Item { public int Id { get; set; } ... public virtual ItemDetail ItemDetail { get; set; } } public class ItemDetail { public int Id { get; set; } public byte[] Bytes { get; set; } } public class Context : DbContext { public DbSet<Item> Items { get; set; } public DbSet<ItemDetail> ItemDetails { get;

Executing a update/insert stored procedure with entity framework 4.1?

耗尽温柔 提交于 2019-12-01 06:40:54
问题 I tried to call a stored procedure from entity framework 4.1 (mvc 3 web application). Its not throwing an exception but the insert/update is not happening? When I manually executed the stored proc it works. CREATE PROCEDURE [dbo].[SP_AddUpdateResponse] @QuestionID int, @UserID int, @AnswerValue nvarchar(2000), @ReviewID int AS MERGE [dbo].[Responses] AS [Target] USING (SELECT @QuestionID, @UserID, @AnswerValue, @ReviewID) AS [Source] ([QuestionID], [UserID], [AnswerValue], [ReviewID] ) ON