I am getting exception mapping a private property.This is the situation:
I have this in Entity.cs:
privat int m_Inactive;
and in EntityMap.cs I have :
Map(x => Reveal.Property<Entity>("m_Inactive")).ColumnName.("INACTIVE");
But I get this error:
System.Reflection.TargetInvocationException: Exception has been thrown
by
the target of an invocation. ---> System.ArgumentException: Not a member access
What could be the reason?
Thanks.
If you follow the examples on the wiki you'll see that you're supposed to use Map(Reveal.Member<YourEntity>("m_Inactive")).
Looks like in the latest version you're supposed to use Reveal.Member since Reveal.Property is obsolete:
Map(Reveal.Member<YourEntity>("m_Inactive"))
Oh, and sort of a "duh" but you'll need to make sure you include FluentNHibernate:
using FluentNHibernate;
And another "duh" but this will work with protected members as well as private.
Related
I'm getting a bit frustrated trying to override the repository of my own Entity.
I need to create a custom repository method to get a list of my entities with special way. One queryBuilder with Having and OrderBy.
Te question is how can I setup my config to say Sylius, take my custom repositor, not the default.
I try this:
sylius_resource:
resources:
dinamic.category:
classes:
model: App\Bundle\SyliusBlogBundle\Entity\PostCategory
repository: App\Bundle\SyliusBlogBundle\Repository\PostCategoryRepository
This is my Repository:
<?php
namespace App\Bundle\SyliusBlogBundle\Repository;
use Doctrine\ORM\EntityRepository;
class PostCategoryRepository extends EntityRepository
{
public function findCategoriesMenu()
{
$queryBuilder = $this->createQueryBuilder('c');
return $queryBuilder
->addSelect('COUNT(p.id) as totalPosts')
->leftJoin('c.posts', 'p')
->andWhere('p.published = true')
->having('totalPosts > 0')
->addGroupBy('p.id')
;
}
}
When I try to use this method, Symfony throws me this error:
An exception has been thrown during the rendering of a template ("Undefined method 'findCategoriesMenu'. The method name must start with either findBy or findOneBy!")
Well you aren't subclassing the correct repository. The ResourceController expects a repository based on the Sylius\Component\Resource\Repository\RepositoryInterface. Since you are subclassing from Doctrine\ORM\EntityRepository that won't be the case.
Your repository should inherit from Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository (or implement the interface yourself).
I answer to the post to paste correctly the response of app/console debug:container dinamic.repository.category
Information for Service "dinamic.repository.category"
=====================================================
------------------ -------------------------------------------------------------------
Option Value
------------------ -------------------------------------------------------------------
Service ID dinamic.repository.category
Class Dinamic\Bundle\SyliusBlogBundle\Repository\PostCategoryRepository
Tags -
Scope container
Public yes
Synthetic no
Lazy no
Synchronized no
Abstract no
Autowired no
Autowiring Types -
------------------ -------------------------------------------------------------------
Since here all it's ok.
When i try to access to Posts list this error appears:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 4 passed to Sylius\Bundle\ResourceBundle\Controller\ResourceController::__construct() must implement interface Sylius\Component\Resource\Repository\RepositoryInterface, instance of Dinamic\Bundle\SyliusBlogBundle\Repository\PostCategoryRepository given, called in /Applications/XAMPP/xamppfiles/htdocs/rosasinbox-sylius/app/cache/dev/appDevDebugProjectContainer.php on line 2767 and defined")
The error of main post appears when the repository config wasn't set. Then my first post was wrong, on config.yml repository value wasn't set.
Now i set it another time and i got this error.
Sorry for the confusion.
I have a simple problem.
I've created a WCF Data Service 5.6 in visual studio 2013, and in its *.svc.cs file, modified line
public class CustomdataService : DataService< /* TODO: put your data source class name here */ >
to connect my entities
public class CustomdataService : DataService< SchedulerEntities >
But when I want to see the service in browser it gives me following error
Request Error
The server encountered an error processing the request. See server logs for more details.
The entity framework is nothing but a single table...
The actual error can be different. In my case I got the same general error message when starting with AdventureWorks2012 database.
So the actual problem can be seen by appending an attribute to the service class as described at here:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class WcfDataServiceAW : EntityFrameworkDataService<AdventureWorks2012Entities> { ... }
Hope it helps someone.
PS. My error is:
The exception message is 'The property 'SpatialLocation' on type 'Address' is of type 'Geography' which is not a supported primitive type.'.
It seems that Entity Framework 6 and WCF Data Services 5.6.0 need some provider to work together, read more on Using WCF Data Services 5.6.0 with Entity Framework 6+.
You can download the provider simply by using NuGet Package Console Manager:
Install-Package Microsoft.OData.EntityFrameworkProvider -Pre
Its version is alpha 2, so in future, search for final release. it worked for me however.
Final thing is, instead of using DataService<T>, you need to use EntityFrameworkDataService<T>. T is the name of your entities.
According to this post, you have to change inherited type of CustomdataService.
Replace the base type of your DataService. For EF 5 or below, your data service should inherit from DataService where T is a DbContext or ObjectContext. For EF 6 or greater, your data service should inherit from EntityFrameworkDataService where T is a DbContext. See What’s the difference between DataService and EntityFrameworkDataService below for more details.
go to edmx, in the diagram, remove all the tables until the only one you want is remain,
then should be okay, cannot have all the tables, this is what I found,
KT Wong
I am using petapoco dataaccess framework, after declaring one new parameter in class file according to database table i am getting the exception below mentioned, in windows service at starting the service.
Service cannot be started. System.MissingMethodException: Method not found: 'System.String projectname.Models.EmailTemplatePOCO.get_Subject()'.
at EmailService.EmailService.StartEmailService()
at EmailService.EmailService.ScheduledService() in d:\Project\Projectname\trunk\projectname\EmailService\EmailService.cs:line 85
at EmailService.EmailService.OnStart(String[] args) in d:\Project\projectname\trunk\projectname\EmailService\EmailService.cs:line 66
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
Does your poco use properties? It will need to eg;
public string Subject {get; set;}
Not sure if you're getting a petapoco error or not
I am trying to do the following bootstrapping:
x.For(Of IErrorLogger).Use(Of ErrorLogger.SQLErrorLogger)().
Ctor(Of IErrorLogger)("backupErrorLogger").Is(ObjectFactory.GetNamedInstance(Of IErrorLogger)("Disk"))
x.For(Of IErrorLogger).Add(
Function()
Return New ErrorLogger.DiskErrorLogger(
CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))
End Function).Named("Disk")
But it shows this error:
StructureMap Exception Code: 200
Could not find an Instance named "Disk" for PluginType Logging.IErrorLogger
I sort of understand why this is happening.. the question is, how do I utilize a named instance within the registry? Maybe something like lazy initialization for the ctor argument for the SQLErrorLogger? I am not sure how to make it happen.
Thanks in advance for any help you can provide.
I found the correct way to do it in the latest version (2.6.1) of StructureMap:
x.For(Of IErrorLogger).Use(Of ErrorLogger.SQLErrorLogger)().
Ctor(Of IErrorLogger)("backupErrorLogger").Is(
Function(c) c.ConstructedBy(Function() ObjectFactory.GetNamedInstance(Of IErrorLogger)("Disk"))
)
x.For(Of IErrorLogger).Add(Function() _
New ErrorLogger.DiskErrorLogger(
CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))
).Named("Disk")
Notice for the Is method of Ctor, we need to provide a func(IContext), and use the IContext.ConstructedBy(Func()) to call ObjectFactory.Get... to successfully register the IErrorLogger in this case.
This is the only way to do it as far as I know. The other Icontext methods such as IsThis and Instance will only work with already registered type.
Your problem is that you are trying to access the Container before it's configured. In order to make structuremap evaluate the object resolution after the configuration you need to provide a lambda to the Is function. The lambda will be evaluated when trying to resolve the type registered.
x.[For](Of ILogger)().Add(Of SqlLogger)().Ctor(Of ILogger)("backupErrorLogger")_
.[Is](Function(context) context.GetInstance(Of ILogger)("Disk"))
x.[For](Of ILogger)().Add(Of DiskLogger)().Ctor(Of String)("errorFileName")_
.[Is](CreateErrorFileName(ServerMapPath(GetAppSetting("ErrorLogFolder"))))_
.Named("Disk")
Disclaimer: I'm not completely up-to-date with the lambda syntax in VB.NET, but I hope I got it right.
Edit:
The working C# version of this I tried myself before posting was this:
ObjectFactory.Initialize(i =>
{
i.For<ILogger>().Add<SqlLogger>()
.Ctor<ILogger>("backup").Is(
c => c.GetInstance<ILogger>("disk"))
.Named("sql");
i.For<ILogger>().Add<DiskLogger>().Named("disk");
});
var logger = ObjectFactory.GetNamedInstance<ILogger>("sql");
I am using NHibernate version 2.0.0.4000.
In one of my queries I wanted to make use of the sql function dateadd to add a number of days. This wasn't registered so I created my own dialect and registered the function as follows:
RegisterFunction("adddays",
new SQLFunctionTemplate(NHibernateUtil.DateTime,
"dateadd(dd, ?1, ?2)"));
The registration gets hit and seems to work fine. I use the function in a DetachedCriteria query as follows:
...
Restrictions.LtProperty("DateColumn1"
Projections.SqlFunction("adddays", NHibernateUtil.DateTime,
Projections.Constant(days),
Projections.Property("DateColumn2"))
...
The criteria is returned from a method and passed of to another query. Upon the execution of the final query I get the following exception:
NHibernate.MappingException was caught
Message="No persister for: NHibernate.Criterion.SqlFunctionProjection"
Source="NHibernate"
StackTrace:
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName,
Boolean throwIfNotFound)
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName)
...
None of the blog posts that I have seen mention this problem. Can anybody help?
Cheers in advance.
Nige.
Solved it.
The problem was caused by my usage elsewhere of Restrictions.Eq rather than Restrictions.EqProperty. The former does not have an overload for (IProjection,IProjection) and so was treating the second projection as an object and passing it to a persister.
Thanks to anyone who investigated this.
Nigel.
For No Persister exception in nhibernet solution is
just give a right click on the respective hbm file ->Properties->change the type Build Action-> to Embedded Resource
with the above step application will working fine