entity-framework-4

Is EntityState.Modified required for an update?

前提是你 提交于 2021-02-20 05:39:29
问题 I've seen a lot of people when updating a record use: ... ms.Status = status; db.Entry(ms).State = EntityState.Modified; db.SaveChanges(); Is this line required? I was able to do an update without it. db.Entry(ms).State = EntityState.Modified; I was wondering what this statement is actually used for if the context already knows it should update that record without you specifying it explicitly then why bother specifying it explicitly? 回答1: It is required if your changes in the entity was done

Unit of Work and EF

你离开我真会死。 提交于 2021-02-11 08:22:49
问题 I'm making an interface following the Unit of Work pattern. My interface looks like this: public interface IDataContext : IDisposable { void SaveChanges(); TSource Create<TSource>(TSource toCreate) where TSource : class; TSource Update<TSource>(TSource toUpdate) where TSource : class; bool Delete<TSource>(TSource toDelete) where TSource : class; IQueryable<TSource> Query<TSource>(); } So far so good. Now I implement it in my Data Layer, which uses EF4 as data provider. I came up with this

Unit of Work and EF

混江龙づ霸主 提交于 2021-02-11 08:22:15
问题 I'm making an interface following the Unit of Work pattern. My interface looks like this: public interface IDataContext : IDisposable { void SaveChanges(); TSource Create<TSource>(TSource toCreate) where TSource : class; TSource Update<TSource>(TSource toUpdate) where TSource : class; bool Delete<TSource>(TSource toDelete) where TSource : class; IQueryable<TSource> Query<TSource>(); } So far so good. Now I implement it in my Data Layer, which uses EF4 as data provider. I came up with this

Unit of Work and EF

淺唱寂寞╮ 提交于 2021-02-11 08:21:47
问题 I'm making an interface following the Unit of Work pattern. My interface looks like this: public interface IDataContext : IDisposable { void SaveChanges(); TSource Create<TSource>(TSource toCreate) where TSource : class; TSource Update<TSource>(TSource toUpdate) where TSource : class; bool Delete<TSource>(TSource toDelete) where TSource : class; IQueryable<TSource> Query<TSource>(); } So far so good. Now I implement it in my Data Layer, which uses EF4 as data provider. I came up with this

Dynamic LINQ Cast issue

廉价感情. 提交于 2021-02-08 08:13:14
问题 When I try to execute this ESQL (Cast int to string) with dynamic linq (from this link) queryable.Where("CAST(PositionID AS Edm.String).Contains(@0)", paramsObj); //PositionID is Int32 it throw exception ')' or ',' expected My Entity Framework version is 4.0. Any idea how to resolve this problem ? Thanks in advance, Brian 回答1: you cann't use as inside function call, try change your code like this queryable.Where("(PositionID.ToString().Contains(@0))", paramsObj); //PositionID is Int32 UPDATE:

Dynamic LINQ Cast issue

泄露秘密 提交于 2021-02-08 08:06:01
问题 When I try to execute this ESQL (Cast int to string) with dynamic linq (from this link) queryable.Where("CAST(PositionID AS Edm.String).Contains(@0)", paramsObj); //PositionID is Int32 it throw exception ')' or ',' expected My Entity Framework version is 4.0. Any idea how to resolve this problem ? Thanks in advance, Brian 回答1: you cann't use as inside function call, try change your code like this queryable.Where("(PositionID.ToString().Contains(@0))", paramsObj); //PositionID is Int32 UPDATE:

Dynamic LINQ Cast issue

会有一股神秘感。 提交于 2021-02-08 08:04:27
问题 When I try to execute this ESQL (Cast int to string) with dynamic linq (from this link) queryable.Where("CAST(PositionID AS Edm.String).Contains(@0)", paramsObj); //PositionID is Int32 it throw exception ')' or ',' expected My Entity Framework version is 4.0. Any idea how to resolve this problem ? Thanks in advance, Brian 回答1: you cann't use as inside function call, try change your code like this queryable.Where("(PositionID.ToString().Contains(@0))", paramsObj); //PositionID is Int32 UPDATE:

Read Oracle SYS_REFCURSOR in C# Entity Framework?

我们两清 提交于 2021-01-29 14:23:30
问题 I have a simple C# console application and its code is like this: using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; using Oracle.ManagedDataAccess.Client; namespace ConsoleApp1 { class Program { static void Main(string[] args) { SHRSContext shrsContext = new SHRSContext(); DbCommand cmd = shrsContext.Database.Connection.CreateCommand(); cmd.CommandText = "PKG_SHRS.GETLOGINATTEMPT";

Extending Entity Framework Model at application runtime

懵懂的女人 提交于 2021-01-29 00:40:55
问题 For a business application, I am providing a base entity model. Thereafter the end user should be able to extend the model for his specific needs. For the base model I want to use database-first approach. But I don't know how to accommodate for allowing user to extend it. One part is to provide a UI for entity model editing and the other is to reflect the changes in the model and database thereafter. Please offer suggestions. EDIT : - Once the entity model is edited and saved, all EF

Extending Entity Framework Model at application runtime

限于喜欢 提交于 2021-01-29 00:36:47
问题 For a business application, I am providing a base entity model. Thereafter the end user should be able to extend the model for his specific needs. For the base model I want to use database-first approach. But I don't know how to accommodate for allowing user to extend it. One part is to provide a UI for entity model editing and the other is to reflect the changes in the model and database thereafter. Please offer suggestions. EDIT : - Once the entity model is edited and saved, all EF