viagra levitra alternatives
New Member
I have problems updating and object with Entity Framework 5.0 using Code First , I have two objects in my code. The class Provider and Image:\[code\] public class Provider { public int ID { get; set; } public string Name { get; set; } public string URL { get; set; } public virtual Image Logo { get; set; } public Provider() { ID = -1; Image = null; }}public class Image{ public int ID { get; set; } public string FileURL { get; set; } public Image() { ID = -1; }}\[/code\]I use code first to persist the objects to Sqlserver database. The object Logo is not required, and it may happen that the user creates a new provider and save it without logo. When the user creates a new provider with a logo, code first works correctly, Provider object and Image are inserted and database, and Provider is created with a foreing key value to table Image. The problem is when the user updates a Provider created without a logo. Updating Provider to Add a Logo to a Provider, when code first is invoked Logo is inserted in table Image but provider object is not updated with the foreing key value to image, Image_ID cotinues to null value after updated.. The sql code generated by code first is:\[code\]exec sp_executesql N'insert [dbo].[Images]([FileURL])values (@0)select [ID]from [dbo].[Images]where @@ROWCOUNT > 0 and [ID] = scope_identity()',N'@0 nvarchar(max) ',@0=N'/data/images/baseimage.png' exec sp_executesql N'update [dbo].[Providers]set [Name] = @0, = @1where ([ID] = @2)',N'@0 nvarch...of the new Image created.Thanks for your help