When using Dapper with Entity Framework, should table constraints be relaxed or disabled?

.net-4.0 dapper edmx entity-framework

Question

I want to plan to do something similar to this.dataSet1.EnforceConstraints = false; using the Entity Framework and Dapper.Net ORM.

In VS2010, I made the models with the following property:

    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.String ethnicname
    {
        get
        {
            return _ethnicname;
        }
        set
        {
            OnethnicnameChanging(value);
            ReportPropertyChanging("ethnicname");
            _ethnicname = StructuralObject.SetValidValue(value, false);
            ReportPropertyChanged("ethnicname");
            OnethnicnameChanged();
        }
    }

... whenvalue is null I encounter a constraint exception at andStructuralObject.SetValidValue... . How can I turn this off, and where?

This is how my data call looks:

    public DAL.Models.PROFILE GetProfile(int profileID)
    {
        using (IDbConnection connection = OpenConnection("MyDBConnectionString"))
        {
            try
            {

                var profiles = connection.Query<DAL.Models.PROFILE>("SELECT * FROM PROFILES WHERE ID=@ID", new { ID = profileID }); // IEnumerable
                var profile = profiles.First<DAL.Models.PROFILE>();

                return profile;
            }
            catch (Exception ex)
            {
                ErrorLogging.Instance.Fatal(ex);
                return null;
            }
        }
    }
1
0
5/25/2012 1:22:37 PM

Accepted Answer

If you use automatically createdEntityObject Based entities, you cannot turn off this validation if you declare the field as non nullable (your database has been marked as such). The second component ofSetValidValue determines if null is acceptable or not.

1
5/25/2012 10:02:15 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow