fluent-interface

How to combine conditions dynamically?

大城市里の小女人 提交于 2019-11-29 05:20:23
This question is an enhancement to the already answered question How to apply multiple filter conditions (simultaneously) on a list? In the above mentioned question we have a method that applied AND operator on all the specifications. This is achieved by using LINQ All operator on the specifications. public static List<Product> GetProductsUisngAndFilters(List<Product> productList, List<Specification<Product>> productSpecifications) { return productList.Where(p => productSpecifications.All(ps => ps.IsSatisfiedBy(p))).ToList(); } We need to create a new method (GetProductsUisngDynamicFilters)

EF Code First prevent property mapping with Fluent API

孤街醉人 提交于 2019-11-29 04:58:32
问题 I have a class Product and a complex type AddressDetails public class Product { public Guid Id { get; set; } public AddressDetails AddressDetails { get; set; } } public class AddressDetails { public string City { get; set; } public string Country { get; set; } // other properties } Is it possible to prevent mapping "Country" property from AddressDetails inside Product class? (because i will never need it for Product class) Something like this Property(p => p.AddressDetails.Country).Ignore();

EF Code First 4.1 - How to configure one to many relationship with default

我的梦境 提交于 2019-11-29 04:40:42
I have a Customer entity which references a collection of Addresses. The complication here is that I want to be able to identify a particular address as the default address. If possible I would like to hold the FK of the default address in the Customer table. This seems more elegant than having a column in the addresses table to identify the default. I am having difficulty with the fluent API in terms of defining this relationship. When I run the following code I get an exception which says: "An error occurred while saving entities that do not expose foreign key properties for their

Fluent interfaces and inheritance in C++

安稳与你 提交于 2019-11-29 04:27:55
I'd like to build a base (abstract) class (let's call it type::base ) with some common funcionality and a fluent interface, the problem I'm facing is the return type of all those methods class base { public: base(); virtual ~base(); base& with_foo(); base& with_bar(); protected: // whatever... }; Now I could make subtypes, e.g.: class my_type : public base { public: myType(); // more methods... }; The problem comes when using those subtypes like this: my_type build_my_type() { return my_type().with_foo().with_bar(); } This won't compile because we're returning base instead of my_type. I know

Unable to determine the principal end of an association - Entity Framework Model First

半腔热情 提交于 2019-11-29 01:41:00
I have created Entity Data Model in Visual Studio. Now I have file with SQL queries and C# classes generated from Model. Question: Classes are generated without annotations or code behind (Fluent API). Is it OK? I tried to run my application but exception was thrown: Unable to determine the principal end of an association between the types 'Runnection.Models.Address' and 'Runnection.Models.User'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations. I read that I can not use Fluent API with "Model First". So what can I

How to store double[] array to database with Entity Framework Code-First approach

本秂侑毒 提交于 2019-11-28 22:26:32
问题 How can I store an array of doubles to database using Entity Framework Code-First with no impact on the existing code and architecture design? I've looked at Data Annotation and Fluent API, I've also considered converting the double array to a string of bytes and store that byte to the database in it own column. I cannot access the public double[] Data { get; set; } property with Fluent API, the error message I then get is: The type double[] must be a non-nullable value type in order to use

Castle Windsor: Auto-register types from one assembly that implement interfaces from another

杀马特。学长 韩版系。学妹 提交于 2019-11-28 21:39:00
I use Castle Windsor as my IoC container . I have an application that has a structure similar to the following: MyApp.Services.dll IEmployeeService IContractHoursService ... MyApp.ServicesImpl.dll EmployeeService : MyApp.Services.IEmployeeService ContractHoursService : MyApp.Services.IContractHoursService ... I use the XML configuration at the moment, and every time I add a new IService/Service pair, I have to add a new component to the XML configuration file. I want to switch all this over to the fluent registration API but haven't worked out exactly the right recipe to do what I want yet.

Entity Framework Code First Case Sensitivity on string PK/FK Relationships

三世轮回 提交于 2019-11-28 12:08:29
I have a fairly simple composite one to many relationship defined using POCO/Fluent API, one column of which is a string. I've discovered that the data in this column in our database is inconsistent in terms of case ie 'abb', 'ABB' - this is our main ERP system and is fed by a variety of sources which are mainly beyond our control. This is leading to problems using EF code first when joining to related tables as the join is silently ignored by EF when the case of PK/FK is different even though SQL Profiler shows the correct SQL being executed and results returned. I'm using WCF so have lazy

Fluent API with inheritance and generics

隐身守侯 提交于 2019-11-28 08:57:11
I'm writing a fluent API to configure and instantiate a series of "message" objects. I have a hierarchy of message types. To be able to access method of subclasses when using the fluent API, I used generics to parametrize the subclasses and make all fluent methods (that start with "with") return the generic type. Note that I omitted most of the body of the fluent method; a lot of configuration goes on in them. public abstract class Message<T extends Message<T>> { protected Message() { } public T withID(String id) { return (T) this; } } The concrete subclasses redefine the generic type

Creating Unique Index with Entity Framework 6.1 fluent API

a 夏天 提交于 2019-11-28 06:44:28
I have a column "Name" that must be unqiue. No foreign key or anything like that. EF 6.1 finally supports creating such indexes via Annotations. That has been discussed already on SO. But it seems it can only be done via annotations in the classes. How do I do that using only the Fluent API? Something like this: public class PersonConfiguration : EntityTypeConfiguration<Person> { public PersonConfiguration() { HasKey(p => p.Id); Property(p => p.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); //not possible? Index(p => p.Name).IsUnique(); //??? } } NOTE: Relevant to EF 6 You