fluent-interface

Entity Framework Code First Mapping Foreign Key Using Fluent API

醉酒当歌 提交于 2019-12-09 10:00:06
问题 I have the situation where a User can have several addresses. Accordingly, I have an ICollection on my user class. But I also want the user to be able to choose a default address. So I've done the following: public class User { public int Id { get; set; } public int? DefaultAddressId { get; set; } [ForeignKey("DefaultAddressId")] public virtual Address DefaultAddress { get; set; } public virtual ICollection<Address> Addresses { get; set; } //properties were removed for purpose of this post }

EF 4.1 RC Many to many relationship in EF CF

故事扮演 提交于 2019-12-09 06:34:59
问题 I have two entities with many to many relationship like this: class author { public int AuthorID{get;set;} public string Name{get;set;} public virtual ICollection<book> books{get;set;} } class book { public int BookID{get;set;} public string Name{get;set;} public virtual ICollection<author> authors{get;set;} } and I have an intermediate table named Bookauthor defined like this: BookAuthor: int int AuthorID int BookID How to map this using FluentAPI Thanks!! 回答1: This was problematic with EDMX

What conventions/idioms/patterns are you using configuring IOC Containers using the new Fluent Interfaces

被刻印的时光 ゝ 提交于 2019-12-09 04:53:27
问题 I am in the middle of moving over a large body of code to Castle Trunk which includes the new fluent interface for configuring the container. Since the project has a huge windsorConfig xml file that is beyond maintainable, I thought I would start to take advantage of this new feature. I know other containers (e.g. StructureMap 2.0) also contain fluent interfaces for container configuration, so this question isn't based around Windsor. My question is what conventions/idioms/patterns are you

php destructor called too soon with fluent interface

拈花ヽ惹草 提交于 2019-12-08 01:34:26
问题 I found a really weird thing about php destructor: basically I have a database management class which loads an adapter using a factory to define which adapter should be loaded (mysql, mysqli, etc.) I'll write down only the part of the code insteresting, as the class itself is way longer but code isn't involved in the current trouble The problem occurs ONLY with mysql (mysqli & pdo works just fine) but for compatibility purposes, getting rid of mysql it's out of question. class manager {

Fluent Entity Framework Mapping

戏子无情 提交于 2019-12-07 22:28:22
问题 Is there any way to perform Fluent EF Mapping like Fluent NHibernate for NHibernate ? 回答1: Entity Framework v4.0 introduces the Code Only concept which is really close to Fluent NHibernate. More information is available here and here in the ADO.NET team blog 来源: https://stackoverflow.com/questions/1845688/fluent-entity-framework-mapping

C# Fluent API With Dynamic Func<> Construction

穿精又带淫゛_ 提交于 2019-12-07 10:54:18
问题 I'm fooling around with creating a small SQL library with a fluent API and want to do something like this: var person = connection.GetOne<Person>("select * from [Person] where [Id] = 1") .WithMany<Pet>("select * from [Pet] where [PersonId] = 1") .WithMany<Address>("select * from [Address] where [PersonId] = 1]") .Build((person, pets, addresses) => { person.Pets = pets; person.Addresses = addresses; return person; }); I've built plenty of fluent API's before but all have been much more simple

Multiplicity constraint violations with optional-required EF Code First + Fluent relationship?

折月煮酒 提交于 2019-12-06 16:05:59
For some reason I had my made my mind a while back on an EF 6 project that I would try to avoid naming foreign keys. I defined much of the model without testing it incrementally and so I have been running into multiplicity and incomplete Fluent API definition issues: A relationship from the 'User_InternalAuth' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'User_InternalAuth_Target' must also in the 'Deleted' state. In one case, here is the code: nModelBuilder.Entity<User>() .HasOptional<InternalAuth>(u => u.InternalAuth) .WithRequired(a => a.User)

Designing Fluent interface methods

久未见 提交于 2019-12-06 14:35:51
I am trying to write a DSL I have methods that return strings but if I want to combine the strings I need to use a + symbol but I would like to call the methods together but I'm unsure how to achieve it I have methods at the moment such as MyStaticClass.Root() MyStaticClass.And() MyStaticClass.AnyInt() which return strings I would like to be able to do Root().And().AnyInt() which result in a string The methods should return a wrapper class. The methods are also instance methods of the wrapper class. Example: class Fluent { private string _value; public Fluent And() { this._value += "whatever";

Fluent Entity Framework Mapping

放肆的年华 提交于 2019-12-06 12:58:18
Is there any way to perform Fluent EF Mapping like Fluent NHibernate for NHibernate ? Entity Framework v4.0 introduces the Code Only concept which is really close to Fluent NHibernate. More information is available here and here in the ADO.NET team blog 来源: https://stackoverflow.com/questions/1845688/fluent-entity-framework-mapping

Ignore Properties in OnModelCreating

泄露秘密 提交于 2019-12-06 12:34:09
问题 I'm attempting to use Bounded (Db) Contexts in Entity Framework 5.0, and I'm having problems excluding a property from one of the classes included in a specific context. Here is the information (I'll shorten for brevity) BaseContext.cs public class BaseContext<TContext> : DbContext where TContext : DbContext { static BaseContext() { Database.SetInitializer<TContext>(null); } protected BaseContext() : base("name=Development") { } } IContext.cs public interface IContext : IDisposable { int