Base solution for your next web application

Activities of "drblakl"

Using EF6

And yes, I've used the GetAllIncluding() which works great!

I'm wondering if it's possible to ensure eager loading of specific children always. Within the repository, or database configuration instead of within the app service or other layers.

Hello!

Using Asp.NET MVC 5 project and wondering what the best practice is to eager load required children of a Repository.

Do we need to make a custom repository to GetAllIncluding(), or is there another way that will load specific required children all the time if available?

Thank you in advance!

Hey all, in case anyone needs, also for checking of best practices I did the following:

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public class TestAttribute : ActionFilterAttribute, ITransientDependency
    {
        private ITestAppService _iTestAppService;
        private IAbpSession _session;

        public TestAttribute() : this(IocManager.Instance.Resolve<ITestAppService>(), IocManager.Instance.Resolve<IAbpSession>())
        {
        }

        public TestAttribute(ITestAppService service, IAbpSession session)
        {
            _iTestAppService = service;
            _session = session;
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.Controller.GetType() == typeof(SpecificController))
            {
                if (_iTestAppService.GetTestItemByUserId(_session.UserId.Value).TestListCheck.Count == 0)
                {
                    filterContext.Result = new RedirectResult("RedirectToSpecificPage");
                }
                base.OnActionExecuting(filterContext);
            }
        }
    }

I added this Attribute Class to a Filters directory within the area it's being used.

Then just added the attribute to the actions where restriction was required.

Please advise if there's a better practice way of achieving the same result.

Thank you!

Hey alper, thanks for the reply, we're using Asp.Net MVC 5 not Core.

Can you please explain or provide an example for Asp.Net MVC 5?

Thank you!

Hello!

I'd like to make a Custom ActionFilterAttribute and within that class use one of my application services, as well as the AbpSession.

How would I go about doing this?

Thank you!

Thanks for the response! I was actually referring more toward the database schema rather than the data if that makes sense. For example, if someone goes in and changes a column, or relationship on the database side, is there a way to detect that within entityframework codefirst to know that the database schema is out of sync with the code base?

Thank you so much! Worked like a charm!

Through messing with my entities the database and entities were not in sync. Just removed them from dbcontext, and added them back as mentioned above and it works great! Thanks again!

Is there a way to determine if the database is out of sync with the entities, for example if the database has been manually modified outside of the code?

Hello all!

I've posted this on stackoverflow related to entityframework but haven't gotten many responses, so I'm hoping one of you can enlighten me. Perhaps my strategy is all wrong or thinking is not quite in the right place. Might just be my lack of understanding of EntityFramework and how it works. I'm okay with using straight data annotations, or OnModelCreating(). I think I'm just missing a few pieces to ensure the chain is inserted properly, and goes from there.

For this example, we have a Student Entity which has a one to one relationship with ImmunizationRecord. ImmunizationRecord has a one to Many relationship to ShotRecord. A student can only have one ImmunizationRecord, but every ImmunizationRecord can have many ShotRecords.

Where I'm at now I currently get the following error on insert of Student.

abp InvalidOperationException: A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'Id'.

Here are my entity snippets:

Student

[Table("tblStudent")]   
    public class Student : FullAuditedEntity, IMustHaveTenant
    {
        public Student()
        {
            ImmunizationRecord = new ImmunizationRecord();
        }

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public override int Id { get => base.Id; set => base.Id = value; }

        public int TenantId { get; set; }
 
        //...
        [ForeignKey(nameof(Id))]
        public virtual ImmunizationRecord ImmunizationRecord { get; set; }      
    }

ImmunizationRecord - Only one per student allowed

[Table("tblImmunizationRecord")]
    public class ImmunizationRecord : FullAuditedEntity, IMustHaveTenant
    {
        public ImmunizationRecord()
        {
            ShotRecords = new HashSet<ShotRecord>();
        }

        [Key, ForeignKey(nameof(ShotRecords))]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public override int Id { get => base.Id; set => base.Id = value; }

        public int TenantId { get; set; }

        public int StudentId { get; set; }

       //...

        public virtual Student Student { get; set; }
        public virtual ICollection<ShotRecord> ShotRecords { get; set; }
    }

ShotRecord - there can be many shot records for each ImmunizationRecord

[Table("tblShotRecord")]
    public class ShotRecord : FullAuditedEntity, IMustHaveTenant
    {
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public override int Id { get => base.Id; set => base.Id = value; }

        public int ImmunizationRecordId { get; set; }

        public int TenantId { get; set; }

        //...

       public virtual ImmunizationRecord ImmunizationRecord  {get; set; }
    }

My DbContext

modelBuilder.Entity<Student>()
                        .HasOptional(s => s.ImmunizationRecord)
                        .WithRequired(z => z.Student);

            modelBuilder.Entity<ShotRecord>().HasRequired(r => r.ImmunizationRecord).WithMany(i => i.ShotRecord).HasForeignKey(l => l.ImmunizationRecordId).WillCascadeOnDelete(false);

Hello!

We'd love to use the AspNetZeroRadTool from within an ASP.NET MVC 5.x & jQuery project however we're having some issues.

I'm hoping this is coming over to the ASP.NET MVC 5.x projects as well.

--

I've copied over files but it seems that the Extension is hard coded to check for Core Project folders.

I also get the error: "No executable found matching command "dotnet-ef"

Please advise.

Thank you

The ideal scenario would be:

Use the ADO.NET Visual Editor / Designer to access tables. This would allow us to easily track changes within the database simply by updating the model from the database.

If we created a new repository would we be able to use Multitenancy and features that are available by using Asp.Net Zero?

Could we ensure multitenancy? If so, how so?

Would we have the same control over these entities we would as if we had created them using the Code First Method?

That's the main thing, I don't want to use the ADO.NET Entity Data Model and lose mass amounts of functionality.

Showing 1 to 10 of 11 entries