entity-framework

How can I use System-Versioned Temporal Table with Entity Framework?

百般思念 提交于 2020-08-22 02:23:11
问题 I can use temporal tables in SQL Server 2016. Entity Framework 6 unfortunately does not know this feature yet. Is there the possibility of a workaround to use the new querying options (see msdn) with Entity Framework 6? I created a simple demo project with an employee temporal table: I used the edmx to map the table to entity (thanks to Matt Ruwe): Everything works fine with pure sql statements: using (var context = new TemporalEntities()) { var employee = context.Employees.Single(e => e

The underlying provider failed on Open and other exceptions with local DbContext variables

守給你的承諾、 提交于 2020-08-20 10:33:19
问题 We have a static DbContext that we use throughout our project. Here is the get method: public static istanbulEntities DbContext { get { string ocKey = "ocm_" + HttpContext.Current.GetHashCode().ToString("x"); if (!HttpContext.Current.Items.Contains(ocKey)) HttpContext.Current.Items.Add(ocKey, new istanbulEntities()); return HttpContext.Current.Items[ocKey] as istanbulEntities; } } We were having exceptions with some of the routine tasks that we have in Global.asax, and these problems were:

Disable publish of EF configuration files to bin folder

可紊 提交于 2020-08-10 23:48:08
问题 I never came across the needs until now to do something about publishing of the XML configuration files that come with EntityFramework referenced projects. Those configuration files contain connection strings that are also within the Web.config of the start-up project - which we do not want right now. I understand that those configuration files are mandatory for EF and models while they are within VS, but since the connection string is taken from the Web.config and not Models.dll.config is

Disable publish of EF configuration files to bin folder

☆樱花仙子☆ 提交于 2020-08-10 23:47:31
问题 I never came across the needs until now to do something about publishing of the XML configuration files that come with EntityFramework referenced projects. Those configuration files contain connection strings that are also within the Web.config of the start-up project - which we do not want right now. I understand that those configuration files are mandatory for EF and models while they are within VS, but since the connection string is taken from the Web.config and not Models.dll.config is

How can I convert a custom function to a sql expression for Entity Framework Core 3.1

為{幸葍}努か 提交于 2020-08-10 20:21:49
问题 I am looking for some guidance/help on how to approach my problem as I'm running out of ideas. I am trying to take a custom extension function and pass it to the database via Entity Framework (EF Core 3.1) using Linq to Entities but I am getting a "{method} could not be translated" error regardless of what I do. I have tried using HasDbFunction along with HasTranslation using this link Thinktecture - Entity Framework Core - Custom Functions (using HasDbFunction) to no avail. I have also tried

Why am I receiving an EntitySqlException when executing a LINQ to Entities query that uses a custom DB Function?

痞子三分冷 提交于 2020-08-10 18:54:26
问题 As you may already know, when using LINQ to Entities with EF6 you can not use Int.TryParse or anything really trying to convert/cast a string to an int. I've created a custom function convention below to mitigate this: Public Class CustomFunctionConvention Implements IConceptualModelConvention(Of EdmModel) Public Sub Apply(item As EdmModel, model As DbModel) Implements IConceptualModelConvention(Of EdmModel).Apply Dim functionParseInt = New EdmFunctionPayload With { .CommandText = String

Why is Automapper.ProjectTo() throwing a null reference exception?

流过昼夜 提交于 2020-08-10 04:02:21
问题 I have a mapping: var config = new MapperConfiguration(cfg => { cfg.CreateMap<Foo, FooDto>() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id)) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name)) .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.PhoneNumbers.Number)) //etc. }); and I'm trying to use it in a unit test calling into some mocked up EF objects: var ids = new List<string>() { "123"; "456"; "789"; }; var data = new List<Foo>(); foreach(var

Why is Automapper.ProjectTo() throwing a null reference exception?

大兔子大兔子 提交于 2020-08-10 04:02:11
问题 I have a mapping: var config = new MapperConfiguration(cfg => { cfg.CreateMap<Foo, FooDto>() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id)) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name)) .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.PhoneNumbers.Number)) //etc. }); and I'm trying to use it in a unit test calling into some mocked up EF objects: var ids = new List<string>() { "123"; "456"; "789"; }; var data = new List<Foo>(); foreach(var

Entity Framework generic expression to selectively hide property

匆匆过客 提交于 2020-08-10 01:13:19
问题 The bounty expires in 4 days . Answers to this question are eligible for a +50 reputation bounty. johnny 5 wants to draw more attention to this question: I'm looking for a simple way to create an expression which excludes large amounts of data, without having to write custom mappings, or having large overhead due to reflection I would like to selectively ignore a property from a table. I have an API which exposes the following methods. public interface IReadService { FullDTO Get(); HeaderDTO[

Expression<Func<object, bool>> as Property

前提是你 提交于 2020-08-09 09:32:40
问题 I am trying to refactor some code for a generic repository, that passes in a filter object that will filter data, as well as page, sort etc. Each inheriting Filter (Such as CustomerFilter) has the option of defining its own Expression Filter which will get applied by the base class in the repository. So the customer filter will have properties like this: public string CustomerId { get; set; } public override Expression<Func<object, bool>> Predicate => c => ((Customer)c).Id == CustomerId; Then