entity framework looking in different table during unittests - entity-framework-5

I have a single DbContext in a library along with entities and their configuration in fluent api.
I use this same context in two different projects.
The first one is a test project and the second one a simple console application.
I execute a query including some of it's relations like this:
var vacancies = (from v in ctx.Vacancies
.Include("Categories")
.Include("Levels")
.Include("Contracts")
.Include("JobTypes"));
Strangely enough the console application works perfectly, however the unittest starts looking in the wrong tables all of a sudden.
Both applications produce very different queries when i look at them.
I'm using EF5 atm and I've been stuck on this for a few days now with not a single clue to what might cause this problem.
EDIT:
The point is i don't do any different queries, i also only have on context and only one connectionstring which i have confirmed during runtime connects to the right database.
All i can say is that i feel like the fluent api has no effect in unittests even though it hits the code just fine like it should.
public class SchedulerContext : BaseContext<SchedulerContext>{
public DbSet<Click> Clicks { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<ContractType> Contracts { get; set; }
public DbSet<JobType> JobTypes { get; set; }
public DbSet<Level> Levels { get; set; }
public DbSet<ExternalMapping> ExternalMappings { get; set; }
public DbSet<GeoName> GeoNames { get; set; }
public DbSet<GeoAlternateName> GeoAlternateNames { get; set; }
public DbSet<Trigger> JobTriggers { get; set; }
public DbSet<RegistryValue> RegistryValues { get; set; }
public DbSet<JobResult> JobResults { get; set; }
public DbSet<JobInfo> JobInfo { get; set; }
public DbSet<JobError> JobErrors { get; set; }
public DbSet<JobNotification> JobNotifications { get; set; }
public DbSet<Company> Customers { get; set; }
public DbSet<Vacancy> Vacancies { get; set; }
public SchedulerContext() {
//this.Configuration.ProxyCreationEnabled = false;
//this.Configuration.LazyLoadingEnabled = false;
}
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
modelBuilder.Configurations.Add(new VacancyEntityTypeConfiguration());
base.OnModelCreating(modelBuilder);
}
}
That is my context.
And my entity configuration:
public class VacancyEntityTypeConfiguration : EntityTypeConfiguration<Vacancy> {
public VacancyEntityTypeConfiguration() {
this.HasMany(c => c.Levels).
WithMany().
Map(
m => {
m.ToTable("VacancyLevels");
});
this.HasMany(c => c.Categories).
WithMany().
Map(
m => {
m.ToTable("VacancyCategories");
});
this.HasMany(c => c.Contracts).
WithMany().
Map(
m => {
m.ToTable("VacancyContractTypes");
});
this.HasMany(c => c.Jobtypes).
WithMany().
Map(
m => {
m.ToTable("VacancyJobTypes");
});
}
}
And the exact method which shows the problem.
public List<Vacancy> GetVacanciesForCustomer(Company customer, bool onlineInclusive) {
using (var ctx = new JHSchedulerContext.SchedulerContext()) {
var vacancies = (from v in ctx.Vacancies.Include("Categories").Include("Levels").Include("Contracts").Include("JobTypes") where v.SourceSite == customer.SourceSite && (v.Online || onlineInclusive == false) select v).ToList();
return vacancies.ToList();
}
}
And the Vacancy class:
public class Vacancy {
public Vacancy()
{
this.Language = "";
}
[SolrUniqueKey("id")]
[Key]
[Required]
public int Id { get; set; }
[StringLength(50, ErrorMessage = "Maximum length 50 characters")]
public string ExternalId { get; set; }
[SolrField("title")]
[StringLength(1024, ErrorMessage = "Maximum length 1024 characters")]
public string Title { get; set; }
[SolrField("company")]
[StringLength(1024, ErrorMessage = "Maximum length 1024 characters")]
public string Company { get; set; }
[StringLength(4096, ErrorMessage = "Maximum length 4096 characters")]
public string CompanyText { get; set; }
[SolrField("location")]
[StringLength(1024, ErrorMessage = "Maximum length 1024 characters")]
public string Location { get; set; }
[SolrField("url")]
[StringLength(1024, ErrorMessage = "Maximum length 1024 characters")]
public string Url { get; set;}
[SolrField("source")]
[StringLength(1024, ErrorMessage = "Maximum length 1024 characters")]
public string SourceSite { get; set; }
private string text;
[SolrField("text")]
[StringLength(4096, ErrorMessage = "Maximum length 4096 characters")]
public string Text {
get {
return StringHelper.TruncateAtWord(text, 500);
//return new String(text.Take(500).ToArray());
//return text.Substring(text.Length < 900 ? 0 : (text.Length / 2), (int)Math.Min(text.Length, 500));
}
set{
text = value;
}
}
[StringLength(4096, ErrorMessage = "Maximum length 4096 characters")]
public string TextProfile { get; set; }
[StringLength(4096, ErrorMessage = "Maximum length 4096 characters")]
public string TextOffer { get; set; }
[NotMapped]
[ScriptIgnore]
public SqlGeography Coordinate {
get
{
if (Latitude.HasValue && Longitude.HasValue)
return SqlGeography.Point(Latitude.Value, Longitude.Value, 4326);
else
return null;
}
}
[SolrField("coordinate_0_coordinate")]
public double? Latitude { get; set; }
[SolrField("coordinate_1_coordinate")]
public double? Longitude { get; set; }
[StringLength(1024, ErrorMessage = "Maximum length 1024 characters")]
public string NormalizedLocation { get; set; }
public DateTime? ScrapedDate { get; set; }
[SolrField("insertdate")]
public DateTime? ImportDate { get; set; }
public DateTime? ExpireDate { get; set; }
[NotMapped]
public string DaysAgo {
get {
if (ImportDate != null)
return (DateTime.Now - (DateTime)ImportDate).Days.ToString();
else {
return "N/A";
}
}
}
[SolrField("category")]
public ICollection<string> CategoryNames {
get { return Categories != null ? Categories.Select(c => c.Name).ToList() : null; }
}
[SolrField("level")]
public ICollection<string> LevelNames {
get { return Levels != null ? Levels.Select(l => l.Name).ToList() : null; }
}
[SolrField("contract")]
public ICollection<string> ContractNames {
get { return Contracts != null ? Contracts.Select(c => c.Name).ToList() : null; }
}
[SolrField("time")]
public ICollection<string> JobTypeNames {
get { return Jobtypes != null ? Jobtypes.Select(c => c.Name).ToList() : null; }
}
public string ContactName { get; set; }
[Required]
public bool Online { get; set; }
[NotMapped]
public int? Distance { get; set; }
public string Language { get; set; }
public string PriorityType { get; set; }
public int NumClicks { get; set; }
[NotMapped]
public string GridContactName {
get{
return string.Format("{0} (Total Clicks:{1})",ContactName,NumClicks);
}
}
public virtual ICollection<Level> Levels { get; set; }
public virtual ICollection<Category> Categories { get; set; }
public virtual ICollection<ContractType> Contracts { get; set; }
public virtual ICollection<JobType> Jobtypes { get; set; }
public override string ToString() {
return string.Format("Id={0} ExternalId={1} Title={2} Company={3} Location={4} Url={5} SourceSite={6} Text={7} NormalizedLocation={8} InsertDate={9} ImportDate={10} DaysAgo={11}",Id, ExternalId,Title,Company,Location,Url, SourceSite,Text,NormalizedLocation,ScrapedDate,ImportDate,DaysAgo);
}
}
And the Level class(all the other relation classes have the same structure(name,id):
public class Level {
[Key]
[Required]
public int Id { get; set; }
[Required]
[StringLength(100, ErrorMessage = "Maximum length 100 characters")]
public string Name { get; set; }
public override string ToString() {
return string.Format("Id={0} Name={1}", Id, Name);
}
}
As far as connection to database goes you'll just have to believe me that i've checked both are connecting to the same database.(I even generated a new database with migrations enabled on this one since we use another context for migrations. That still had the exact same issue).
To clarify:
The unittest looks for table: CategoryVacancies.
The console application or even my windows service i use this in look for the right table: VacancyCategories.

Related

Loading multiple levels of nested navigation and collection properties with proxy disabled

I'm having a hard time figuring out how to do queries with levels of alternating collection and navigation properties with proxy and lazy loading disabled to serialize the result.
public ApplicationDbContext()
: base("Debug")
{
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}
The entities look like this (omitting non-navigation or non-collections):
public class Comprobante: ComprobanteGeneric
{
}
public class ComprobanteGenericStructure
public int Id { get; set; }
[Required]
public virtual Conceptos Conceptos { get; set; }
}
public class Conceptos
{
public Conceptos()
{
Concepto = new List<Concepto>();
}
[ForeignKey("Comprobante")]
public int Id { get; set; }
[Required]
public virtual ICollection<Concepto> Concepto { get; set; }
public virtual Comprobante Comprobante { get; set; }
}
public class Concepto :RelatedComprobante
{
[Key]
public int Id { get; set; }
public virtual OrderOfImpuestosForConceptos Impuestos { get; set; }
public virtual Conceptos Conceptos { get; set; }
}
public class RelatedComprobante
{
[ForeignKey("Comprobante")]
public int ComprobanteId { get; set; }
public virtual Comprobante Comprobante { get; set; }
}
public class OrderOfImpuestosForConceptos : RelatedComprobante
{
public int Id { get; set; }
public virtual TrasladosNode Traslados { get; set; }
public virtual Retenciones Retenciones { get; set; }
}
public class TrasladosNode : RelatedComprobante
{
public TrasladosNode()
{
Traslado = new HashSet<Traslado>();
}
[Key]
public int Id { get; set; }
[Required]
public virtual ICollection<Traslado> Traslado { get; set; }
}
public class Traslado : RelatedComprobante
{
public int Id { get; set; }
public virtual TrasladosNode TrasladosNode { get; set; }
}
public class Retenciones : RelatedComprobante
{
public Retenciones()
{
Retencion = new List<Retencion>();
}
public int Id { get; set; }
[Required]
public virtual ICollection<Retencion> Retencion { get; set; }
}
public class Retencion : RelatedComprobante
{
public int Id { get; set; }
public virtual Retenciones Retenciones { get; set; }
}
I need the whole graph. With lazy loading enabled it returns it all eventually but serialization takes several seconds and several queries to DB. I disabled it and tried the following query:
comprobantes = _db.Comprobante
.Include(c => c.Conceptos.Concepto.Select(co => co.Impuestos.Retenciones).Select(r=>r.Retencion))
.Include(c => c.Conceptos.Concepto.Select(co => co.Impuestos.Traslados).Select(t => t.Traslado));
However I get an empty concepto list:
[{
"id": 324,
"conceptos": {
"concepto": []
}
},
{
"id": 340,
"conceptos": {
"concepto": []
}
}
}]
Even simpler queries like the following yield the exact same results:
comprobantes = _db.Comprobante
.Include(c => c.Conceptos.Concepto.Select(co => co.Impuestos));
I know is not the serialization for when I inspect the object while debugging is empty:
What am I doing wrong?
Thanks to David comment I was able to build a working query(es):
var comprobantes = _db.Comprobante
.Include(b => b.Conceptos.Concepto.Select(c => c.Impuestos.Retenciones.Retencion))
.Include(b => b.Conceptos.Concepto.Select(c => c.Impuestos.Traslados.Traslado));
foreach (var comprobante in comprobantes)
{
_db.ComprobanteTraslado.Where(t => t.ComprobanteId == comprobante.Id);
_db.ComprobanteRetencion.Where(r => r.ComprobanteId == comprobante.Id);
}

AutoMapper 6 - How can I create a mapping that ignore and map a list of object

I'm a little newbie on AutoMapper, I don't find almost nothing about v6.0 on Stackoverflow and Github. I need help on this problem
I have this two Entities:
public class DocFinanceiro
{
public int AutoId { get; set; }
public virtual ICollection<QuitacaoDocFinan> QuitacoesDocFinan { get; set; }
}
public class QuitacaoDocFinan
{
public int AutoId { get; set; }
public int DocFinanceiroId { get; set; }
public virtual DocFinanceiro DocFinanceiro { get; set; }
public decimal ValorTotal { get; set; }
}
}
And his ViewModels:
public class DocFinanceiroViewModel
{
public DocFinanceiroViewModel()
{
ValorPago = QuitacoesDocFinan.Where(x => x.Cancelada == false).Sum(x => x.ValorTotal);
}
public virtual ICollection<QuitacaoDocFinanViewModel> QuitacoesDocFinan { get; set; }
public decimal ValorPago { get; set; }
}
public class QuitacaoDocFinanViewModel
{
public int AutoId { get; set; }
public int DocFinanceiroId { get; set; }
public virtual DocFinanceiroViewModel DocFinanceiro { get; set; }
public decimal ValorTotal { get; set; }
}
And mapping between DocFinanceiro and DocFinanceiroViewModel:
public class DomainToViewModelMappingProfile : Profile
{
public DomainToViewModelMappingProfile()
{
CreateMap<DocFinanceiro, DocFinanceiroViewModel>().ForMember(x => x.ValorPago, y => y.Ignore())
.MaxDepth(3)
.PreserveReferences();
CreateMap<QuitacaoDocFinan, QuitacaoDocFinanViewModel>();
}
}
This mapping works when I set only one of these property
.ForMember(x => x.ValorPago, y => y.Ignore())
or
.MaxDepth(1).PreserveReferences();
, but when I try two cause an exception. I search on everywhere, but no success.
And controller where that I make the mapping:
var documentos = Mapper.Map<IEnumerable<DocFinanceiro>, IEnumerable<DocFinanceiroViewModel>>(*repository*);
Sorry if make some mistake, but I don't what to do...
You are trying to access QuitacoesDocFinan collection in DocFinanceiroViewModel constructor before initializing. Your DocFinanceiroViewModel should be something like this:
public class DocFinanceiroViewModel
{
public virtual ICollection<QuitacaoDocFinanViewModel> QuitacoesDocFinan { get; set; }
public decimal ValorPago
{
get
{
return QuitacoesDocFinan.Where(x => x.Cancelada == false).Sum(x => x.ValorTotal);
}
}
}

Error 400.0 when returning DTO in Controller and Azure Mobile Client Sync Table

Since the object we need in the Mobile Client needs to access its related/associated objects, we decided to return an objectDTO instead of the object when the GetAllObjects method in the controller is called.
Using Postman to query the Backend Server results to the proper behaviour, the retrieved list has all the properties of the DTO.
Problem arises when using the Mobile Client. According to the logs, an "HTTP Error 400.0 - Bad Request" happened and "The request could not be understood by the server due to malformed syntax." is indicated under "More Information."
I dont know why this error happened. I updated the Object class in the Client App to match the ObjectDTO class in the server. For comparison:
ObjectDTO in Server
public class SaleDto
{
public string Id { get; set; }
public string ProductId { get; set; }
public string PromoterId { get; set; }
public string StoreId { get; set; }
public string PaymentMethodId { get; set; }
public bool CorporateSale { get; set; }
public DateTime? DateSold { get; set; }
public double PriceSold { get; set; }
public int QuantitySold { get; set; }
public string Remarks { get; set; }
public bool Deleted { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public byte[] Version { get; set; }
public string ProductSku { get; set; }
public string ProductPartNumber { get; set; }
public string StoreName { get; set; }
public string PaymentMethodName { get; set; }
}
Object Model in Client App
public class Sale
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "productId")]
public string ProductId { get; set; }
[JsonProperty(PropertyName = "promoterId")]
public string PromoterId { get; set; }
[JsonProperty(PropertyName = "storeId")]
public string StoreId { get; set; }
[JsonProperty(PropertyName = "paymentMethodId")]
public string PaymentMethodId { get; set; }
[JsonProperty(PropertyName = "corporateSale")]
public bool CorporateSale { get; set; }
[JsonProperty(PropertyName = "dateSold")]
public DateTime? DateSold { get; set; }
[JsonProperty(PropertyName = "priceSold")]
public double PriceSold { get; set; }
[JsonProperty(PropertyName = "quantitySold")]
public int QuantitySold { get; set; }
[JsonProperty(PropertyName = "remarks")]
public string Remarks { get; set; }
[JsonProperty(PropertyName = "deleted")]
public bool Deleted { get; set; }
[JsonProperty(PropertyName = "createdAt")]
public DateTime CreatedAt { get; set; }
[JsonProperty(PropertyName = "updatedAt")]
public DateTime UpdatedAt { get; set; }
[JsonProperty(PropertyName = "version")]
public string Version { get; set; }
[JsonProperty(PropertyName = "productSku")]
public string ProductSku { get; set; }
[JsonProperty(PropertyName = "productPartNumber")]
public string ProductPartNumber { get; set; }
[JsonProperty(PropertyName = "storeName")]
public string StoreName { get; set; }
[JsonProperty(PropertyName = "paymentMethodName")]
public string PaymentMethodName { get; set; }
public virtual Product Product { get; set;}
public virtual Store Store { get; set; }
public virtual PaymentMethod PaymentMethod { get; set; }
}
Or it might be because of the Sync Tables? Here's the code that handles syncing (stuff has been omitted for brevity)
public class DataStore
{
private static DataStore _instance;
public MobileServiceClient MobileService { get; set; }
IMobileServiceSyncTable<Sale> saleTable;
public static DataStore Instance
{
get
{
if (_instance == null)
{
_instance = new DataStore();
}
return _instance;
}
}
private DataStore()
{
MobileService = new MobileServiceClient("url");
var store = new MobileServiceSQLiteStore("tabletable.db");
store.DefineTable<Sale>();
MobileService.SyncContext.InitializeAsync(store);
saleTable = MobileService.GetSyncTable<Sale>();
}
public async Task<Sale> AddSaleAsync(Sale sale)
{
await saleTable.InsertAsync(sale);
bool wasPushed = await SyncSalesAsync();
if (wasPushed) return null;
return sale;
}
public async Task<List<Sale>> GetSalesAsync(int take = 20, int skip = 0)
{
IEnumerable<Sale> items = await saleTable
.Where(sale => !sale.Deleted)
.OrderByDescending(sale => sale.CreatedAt)
.Take(take)
.Skip(skip)
.ToEnumerableAsync();
return new List<Sale>(items);
}
public async Task<bool> SyncSalesAsync()
{
ReadOnlyCollection<MobileServiceTableOperationError> syncErrors = null;
bool wasPushed = true;
try
{
await MobileService.SyncContext.PushAsync();
await saleTable.PullAsync("allSales", saleTable.CreateQuery());
}
catch (Exception e)
{
Debug.WriteLine(#"/Sale/ Catch all. Sync error: {0}", e.Message);
Debug.WriteLine(e.StackTrace);
}
return wasPushed;
}
}
Any kind of help will be much appreciated.
Having SaleDto extend/implement EntityData solved the problem
public class SaleDto : EntityData

Complex Automapper Configuration

I'm mapping from an existing database to a DTO and back again use Automapper (4.1.1) and I've hit a few small problems.
I have a (simplified) model for the database table:
public class USER_DETAILS
{
[Key]
public string UDT_LOGIN { get; set; }
public string UDT_USER_NAME { get; set; }
public string UDT_INITIALS { get; set; }
public string UDT_USER_GROUP { get; set; }
public decimal UDT_CLAIM_LIMIT { get; set; }
public string UDT_CLAIM_CCY { get; set; }
}
and a DTO object:
public class User
{
public string Login { get; set; }
public string UserName { get; set; }
public string Initials { get; set; }
public string UserGroup { get; set; }
public double ClaimLimit { get; set; }
public string ClaimCurrency { get; set; }
}
I've created a profile
public class FromProfile : Profile
{
protected override void Configure()
{
this.RecognizePrefixes("UDT_");
this.ReplaceMemberName("CCY", "Currency");
this.SourceMemberNamingConvention = new UpperUnderscoreNamingConvention();
this.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
this.CreateMap<decimal, double>().ConvertUsing((decimal src) => (double)src);
this.CreateMap<USER_DETAILS, User>();
}
}
However, it seems that Automapper doesn't like combining this many settings in the config. Even simplifying the models, I can't get
this.RecognizePrefixes("UDT_");
this.ReplaceMemberName("CCY", "Currency");
to work together, and whilst
this.CreateMap<decimal, double>().ConvertUsing((decimal src) => (double)src);
works ok with the models in the test, it fails when using it against a database.
Is there a way to get all this to work together, or should I fall back to using ForMember(). I was really hoping I could get this working as there are a lot of tables in this system, and I'd rather not have to do each one individually.
You will need to extend this for other types, only tested with strings, I have an extension method that does all the work and looks for unmapped properties.
public class USER_DETAILS
{
public string UDT_LOGIN { get; set; }
public string UDT_USER_NAME { get; set; }
public string UDT_INITIALS { get; set; }
public string UDT_USER_GROUP { get; set; }
// public decimal UDT_CLAIM_LIMIT { get; set; }
public string UDT_CLAIM_CCY { get; set; }
}
public class User
{
public string Login { get; set; }
public string UserName { get; set; }
public string Initials { get; set; }
public string UserGroup { get; set; }
//public double ClaimLimit { get; set; }
public string ClaimCurrency { get; set; }
}
public static class AutoMapperExtensions
{
public static IMappingExpression<TSource, TDestination>
CustomPropertyMapper<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression)
{
var sourceType = typeof(TSource);
var destinationType = typeof(TDestination);
var existingMaps = Mapper.GetAllTypeMaps().First(x => x.SourceType == sourceType && x.DestinationType == destinationType);
var properties = sourceType.GetProperties();
foreach (var property in existingMaps.GetUnmappedPropertyNames())
{
var similarPropertyName =
properties.FirstOrDefault(x => x.Name.Replace("_", "").Replace("UDT", "").ToLower().Contains(property.ToLower()));
if(similarPropertyName == null)
continue;
var myPropInfo = sourceType.GetProperty(similarPropertyName.Name);
expression.ForMember(property, opt => opt.MapFrom<string>(myPropInfo.Name));
}
return expression;
}
}
class Program
{
static void Main(string[] args)
{
InitializeAutomapper();
var userDetails = new USER_DETAILS
{
UDT_LOGIN = "Labi-Login",
UDT_USER_NAME = "Labi-UserName",
UDT_INITIALS = "L"
};
var mapped = Mapper.Map<User>(userDetails);
}
static void InitializeAutomapper()
{
Mapper.CreateMap<USER_DETAILS, User>().CustomPropertyMapper();
}
}
}

How to perform a more complex query with AutoQuery

Given the following definitions from a ServiceStack endpoint:
public class LoanQueue
{
public int LoanId { get; set; }
public DateTime Submitted { get; set; }
public DateTime Funded { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Fico { get; set; }
public int Fraud { get; set; }
public int CDS { get; set; }
public int IDA { get; set; }
public string Income { get; set; }
public string Liabilities { get; set; }
public string Agent { get; set; }
public string Status { get; set; }
public string State { get; set; }
public string Product { get; set; }
public string Comment { get; set; }
}
public enum DateType
{
None,
Submitted,
Funded
}
[Route("/loan/queue/search", "GET")]
public class LoanQueueQueryGet : QueryBase<LoanQueue>
{
public DateType DateType { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public string AgentUserName { get; set; }
public Languange Languange { get; set; }
public bool WorkingLoan { get; set; }
public bool MicrobusinessLoan { get; set; }
public LoanStatus LoanStatus { get; set; }
}
public object Get(LoanQueueQueryGet request)
{
if (request == null) throw new ArgumentNullException("request");
var profiler = Profiler.Current;
using (profiler.Step("LoanServices.LoanQueue"))
{
SqlExpression<LoanQueue> q = AutoQuery.CreateQuery(request, Request.GetRequestParams());
QueryResponse<LoanQueue> loanQueueResponse = AutoQuery.Execute(request, q);
return loanQueueResponse;
}
}
My question is this, "Is it even possible to run conditional logic based on the request object in the service impl"? e.g.
If DateType == DateType.Submitted
then query the Submitted property on the LoanQueue with a BETWEEN clause (StartDate/EndDate) or
If DateType == DateType.Funded
then query the Funded property on the LoanQueue with a BETWEEN clause (StartDate/EndDate).
My guess is that I'm trying to bend AutoQuery too far and would be better served just coding it up the old fashion way. I really like the baked-in features of the AutoQuery plugin and I'm sure there will be times when it will suit my needs.
Thank you,
Stephen
AutoQuery will ignore any unmatched fields so you're able to use them to extend your populated AutoQuery with additional custom logic, e.g:
public object Get(LoanQueueQueryGet request)
{
var q = AutoQuery.CreateQuery(request, Request.GetRequestParams());
if (request.DateType == DateType.Submitted)
{
q.And(x => x.Submitted >= request.StartDate && x.Submitted < request.EndDate);
}
else
{
q.And(x => x.Funded >= request.StartDate && x.Funded < request.EndDate);
}
var loanQueueResponse = AutoQuery.Execute(request, q);
return loanQueueResponse;
}

Resources