Using View with Linked Server (Oracle) on Entity Framework (.NET)

One of the issue I came across on Entity Framework was pulling a view that consist of a linked server table (Oracle). When I added the view, I was getting the following error. "The table/view LINKED_SERVER_VIEW does not have a primary key defined and no valid primary key could be inferred. This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it." I needed this view as readonly. Only solution that worked was using ISNULL to define a primary key on the view. You will have to create a view like this for Entity Framework to understand the primary key. CREATE VIEW LINKED_SERVER_VIEW AS SELECT ISNULL(PRIMAYKEYCOLUMN, 0) as COL1, OTHERCOLUMN from LINKEDSERVER..SCHEMA.TABLENAME I believe the best approach is to actually fix the table or the model itself and add an actual primary key. However, sometime you will have to work on a database that a client does not want to change and you will have to deal with issues like this. Hope this solution works for you. If you have better solution, feel free to comment.
FacebookTwitterGoogle+Share

JQuery Validation for MMMYY using regex

Here is a JQuery validation for MMMYY format. The month name are case sensitive. Enjoy.
<script type="text/javascript">
$().ready(function () {
 
  $.validator.addMethod("mmmyy", function (value, element) {
    return this.optional(element) || /^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(d{2})$/.test(value);
  }, "This field must contain month and year in MMMYY format.");
 
  $("#formname").validate({
    rules: {
      textboxid: {
        required: true,
        mmmyy: true
      }
    },
 
    messages: {
      textboxid: {
        required: "This field is required."
        //Use default error from the method. If you would like to override the error you can add mmmyy: "custom error message" here
      }
    }
  });
});
</script>
 
<input id="textboxid" name="textboxid" type="text" />