entity-framework

Update and Add Child Rows at same time with Entity Framework

心已入冬 提交于 2020-01-13 10:22:32
问题 i´m having some troubles when it comes to modify and add child rows at the same time. I´m using the technique from the answer: stackoverflow.com/questions/5557829/.... The problem is in the following code: public void EditReport(tbl_inspection inspection) { foreach (var roll in inspection.tbl_inspection_roll) { container.tbl_inspection_roll.Attach(roll); container.ObjectStateManager.ChangeObjectState(roll, (roll.id_inspection_roll == 0) ? EntityState.Added : EntityState.Modified); } container

Update and Add Child Rows at same time with Entity Framework

坚强是说给别人听的谎言 提交于 2020-01-13 10:22:20
问题 i´m having some troubles when it comes to modify and add child rows at the same time. I´m using the technique from the answer: stackoverflow.com/questions/5557829/.... The problem is in the following code: public void EditReport(tbl_inspection inspection) { foreach (var roll in inspection.tbl_inspection_roll) { container.tbl_inspection_roll.Attach(roll); container.ObjectStateManager.ChangeObjectState(roll, (roll.id_inspection_roll == 0) ? EntityState.Added : EntityState.Modified); } container

How to observe the Add action of DbSet<T>?

試著忘記壹切 提交于 2020-01-13 10:05:26
问题 I has two classes named Contact and ContactField as following. When the ContactField is added into Contact , I hope to assign SortOrder to ContactField automatically. Do I need to inherit DbSet and customize the Add method ? How to achieve it ? public class Foo { private MyDbContext _db = new MyDbContext(); public void HelloWorld() { Contact contact = ....; //< A contact from database. ContactField field = ....; ///< A new field .... ///< assign other properties into this `field` field

EF5 Code First and RIA Services Silverlight “Object reference not set to an instance of an object” error building client

坚强是说给别人听的谎言 提交于 2020-01-13 10:05:02
问题 I am working on setting up a new project using Code First for entity framework 5 in silverlight using RIA services. I have created a test project due to some issues I have encountered and will post the code below. Namely, I get an 'Object reference not set to an instance of an object' error anytime I attempt to build the silverlight client project which should generate the client proxy classes. Just to be clear, this error is not while running or debugging the application, but when building

EF5 Code First and RIA Services Silverlight “Object reference not set to an instance of an object” error building client

点点圈 提交于 2020-01-13 10:04:26
问题 I am working on setting up a new project using Code First for entity framework 5 in silverlight using RIA services. I have created a test project due to some issues I have encountered and will post the code below. Namely, I get an 'Object reference not set to an instance of an object' error anytime I attempt to build the silverlight client project which should generate the client proxy classes. Just to be clear, this error is not while running or debugging the application, but when building

EF5 Code First and RIA Services Silverlight “Object reference not set to an instance of an object” error building client

夙愿已清 提交于 2020-01-13 10:04:16
问题 I am working on setting up a new project using Code First for entity framework 5 in silverlight using RIA services. I have created a test project due to some issues I have encountered and will post the code below. Namely, I get an 'Object reference not set to an instance of an object' error anytime I attempt to build the silverlight client project which should generate the client proxy classes. Just to be clear, this error is not while running or debugging the application, but when building

EF 6: mapping complex type collection?

若如初见. 提交于 2020-01-13 09:59:05
问题 Does EF 6 (code first) supports complex type collection(Value Object collections) mappings? I know that it supports Complex types, but haven't still found an example where we have a collection of complex types. For instance, suppose you have an entity called Student, which has a collection of contacts. With NH, I can simply say that Student has a collection of contacts and that contact is a component (equivalent to complex type in ef). Can this be done with EF without changing contact to an

EF SQL changed when passing predicate as Parameter to Where Clause

微笑、不失礼 提交于 2020-01-13 09:21:53
问题 EF is generating different SQL for the for two similar statements listed below var test = dbcontext.Persons.GetAll() .Where(c => c.PersonID == 2) .Select(c => c.PersonName) .FirstOrDefault();` Generated SQL: SELECT [Limit1].[PersonName ] AS [PersonName ] FROM (SELECT TOP (1) [Extent1].[PersonName ] AS [PersonName ] FROM [dbo].[ApplicationRequest] AS [Extent1] WHERE [Extent1].[PersonID ] = @p__linq__0) AS [Limit1]',N'@p__linq__0 uniqueidentifier',@p__linq__0= "2" I am using the above

EF SQL changed when passing predicate as Parameter to Where Clause

﹥>﹥吖頭↗ 提交于 2020-01-13 09:21:39
问题 EF is generating different SQL for the for two similar statements listed below var test = dbcontext.Persons.GetAll() .Where(c => c.PersonID == 2) .Select(c => c.PersonName) .FirstOrDefault();` Generated SQL: SELECT [Limit1].[PersonName ] AS [PersonName ] FROM (SELECT TOP (1) [Extent1].[PersonName ] AS [PersonName ] FROM [dbo].[ApplicationRequest] AS [Extent1] WHERE [Extent1].[PersonID ] = @p__linq__0) AS [Limit1]',N'@p__linq__0 uniqueidentifier',@p__linq__0= "2" I am using the above

Build error when using VS 11, .NET 4.5 and Entity Framework

佐手、 提交于 2020-01-13 09:16:49
问题 In Visual Studio 2010, my solution was using .NET 4.2 (Entity Framework June 2011 CTP) so I could use spatial types in Entity Framework. When I upgraded to Visual Studio 11 Beta, it wouldn't build because of conflicts between the 4.2 and 4.5 framework so I uninstalled 4.2. Now I get this error when I build: Error 209: Currently, spatial types are only supported when used in CSDL files that have the UseStrongSpatialTypes annotation with a false value on their root Schema element. Anyone know