fluent-interface

Reusing a column for a required property with Entity Framework 6.0, Fluent API, and DataAnnotations

≡放荡痞女 提交于 2019-12-11 12:19:08
问题 I have a base class public class BaseClass { public int Id {get; set;} } and two derived classes public class Foobar: BaseClass { [Required] public int Whatever {get; set;} } public class Snafu: BaseClass { [Required] public int Whatever {get; set;} } I'm using Table Per Hierarchy inheritance and trying to cut down on my duplicate columns, so with Fluent API I've mapped them like so: modelBuilder.Entity<Foobar>().Property(fb => fb.Whatever).HasColumnName("Whatever"); modelBuilder.Entity<Snafu

Issue With Fluent Nhibernate Automapping and Guids / UniqueIdentifiers as Primary Key Fields

爱⌒轻易说出口 提交于 2019-12-11 10:19:48
问题 I am attempting to use the Fluent-NHibernate automapping functionality (in the latest version of the software) and am running into problems using Guids as the Primary Key fields. If I use integer fields for the primary keys, the tables are generated successfully and all Nhibernate functionality seems to work fine. FYI, I am using NHibernate to generate my database tables. Here are a couple of classes with integer IDs. using System; using System.Collections; using System.Collections.Generic;

Proxy Authentication With Fluent API Request?

痞子三分冷 提交于 2019-12-10 17:07:49
问题 I am currently using a Get Request with proxy information: String result1 = Request.Get("_http://somehost/") .version(HttpVersion.HTTP_1_1) .connectTimeout(1000) .socketTimeout(1000) .viaProxy(new HttpHost("myproxy", 8080)) .execute().returnContent().asString(); The result is a "Proxy Authentication Required" error. I believe a username and password is required from the server making the request? If so, how do I add that detail? I have never used the Fluent API before. 回答1: You need a

entity framework code first attributes in combination with fluent api configurations

☆樱花仙子☆ 提交于 2019-12-10 13:46:46
问题 Can I use code first attributes in combination with fluent-API configurations for my entities in Entity Framework? Thank you. 回答1: Yes you can. I generally prefer to define some constraints (for example, making a property required by using [Required] or to define a length for a string property by using StringhLength(1, 10) ): [Required] [StringLentgh(1,10)] public string BookName {get;set;} On the other hand, I generally use fluent api to define the relationships (for example, 1-to-many

Castle Windsor Fluent Registration - What does Pick() do?

回眸只為那壹抹淺笑 提交于 2019-12-10 13:40:07
问题 When using auto-registration with castle windsor I see people doing things like _container.Register( AllTypes.Pick().FromAssembly(Assembly.GetExecutingAssembly()) .WithService.FirstInterface()); For the life of me I can't figure out what the Pick() method does nor can I find any documentation. Can anyone explain it to me? 回答1: Pick(IEnumerable<Type>) is a synonym for From(IEnumerable<Type>) , i.e. it selects the specified types as registration targets. AllTypes.Pick() is the same as AllTypes

Register an Interceptor with Castle Fluent Interface

跟風遠走 提交于 2019-12-10 10:46:41
问题 I am trying to implement nhibernate transaction handling through Interceptors and couldn’t figure out how to register the interface through fluent mechanism. I see a Component.For<ServicesInterceptor>().Interceptors but not sure how to use it. Can someone help me out? This example seemed a little complex. 回答1: You do it in two steps: You need to register the interceptor as a service in the container: container.Register(Component.For<MyInterceptor>()); You register the component you want to

OOP problem: Extending a class, override functions and jQuery-like syntax

↘锁芯ラ 提交于 2019-12-10 09:39:44
问题 I have an OOP related problem with Flash, actionscript 3. It's a personal project, and I am looking for a design pattern or workaround for this problem, and my goal is to learn new things. I have created a class called Chain. I created this util-class to make delayed function calling easy. You can make a chain of functions, by adding them with a delay in milliseconds. This chain can be executed multiple times, even in reversed order. This class has functions which returns itself. That makes

Unable to send embedded image in email using FluentEmail

醉酒当歌 提交于 2019-12-09 16:45:10
问题 I'm using FluentEmail in ASP.NET core 2.0 class library which will be sending the Email notification. Below is the sample code I have tried till now: using FluentEmail.Core; using FluentEmail.Razor; using FluentEmail.Smtp; using System; using System.IO; using System.Net.Mail; using System.Net.Mime; namespace FluentEmail { public class EmailNotification : IEmailNotification { public bool SendEmailNotification() { try { //Setup Default sender befault sending the email. SmtpClient smtpClient =

Do fluent interfaces significantly impact runtime performance of a .NET application?

*爱你&永不变心* 提交于 2019-12-09 15:29:14
问题 I'm currently occupying myself with implementing a fluent interface for an existing technology, which would allow code similar to the following snippet: using (var directory = Open.Directory(@"path\to\some\directory")) { using (var file = Open.File("foobar.html").In(directory)) { // ... } } In order to implement such constructs, classes are needed that accumulate arguments and pass them on to other objects. For example, to implement the Open.File(...).In(...) construct, you would need two

PHP OOP: Chainable objects?

▼魔方 西西 提交于 2019-12-09 10:23:13
问题 I have tried to find a good introduction on chainable OOP objects in PHP, but without any good result yet. How can something like this be done? $this->className->add('1','value'); $this->className->type('string'); $this->classname->doStuff(); Or even: $this->className->add('1','value')->type('string')->doStuff(); Thanks a lot! 回答1: The key is to return the object itself within each method: class Foo { function add($arg1, $arg2) { // … return $this; } function type($arg1) { // … return $this;